···132132func (q *Queue) SetIndexed(opts IndexOptions, state indexState) {
133133 q.mu.Lock()
134134 item := q.get(opts.RepoID)
135135- item.setIndexState(state)
135135+136136+ item.indexState = state
136137 if state != indexStateFail {
137138 item.indexed = reflect.DeepEqual(opts, item.opts)
138139 }
140140+139141 if item.heapIdx >= 0 {
140142 // We only update the position in the queue, never add it.
141143 heap.Fix(&q.pq, item.heapIdx)
142144 }
145145+143146 q.mu.Unlock()
144147}
145148···179182 if item.heapIdx >= 0 {
180183 heap.Remove(&q.pq, item.heapIdx)
181184 }
182182- item.setIndexState("")
185185+186186+ item.indexState = ""
187187+183188 delete(q.items, item.opts.RepoID)
184189 count++
185190 }
···216221 q.pq = make(pqueue, 0)
217222}
218223219219-// setIndexedState will set indexedState and update the corresponding metrics
220220-// if the state is changing.
221221-func (item *queueItem) setIndexState(state indexState) {
222222- if state == item.indexState {
223223- return
224224- }
225225- if item.indexState != "" {
226226- metricIndexState.WithLabelValues(string(item.indexState)).Dec()
227227- }
228228- item.indexState = state
229229- if item.indexState != "" {
230230- metricIndexState.WithLabelValues(string(item.indexState)).Inc()
231231- }
232232-}
233233-234224// pqueue implements a priority queue via the interface for container/heap
235225type pqueue []*queueItem
236226···286276 Name: "index_queue_cap",
287277 Help: "The number of repositories tracked by the index queue, including popped items. Should be the same as index_num_assigned.",
288278 })
289289- metricIndexState = promauto.NewGaugeVec(prometheus.GaugeOpts{
290290- Name: "index_state_count",
291291- Help: "The count of repositories per the state of the last index.",
292292- }, []string{"state"})
293279)