@@ -261,32 +261,19 @@ func (i *IndexingTask) CanAccept(ids []harmonytask.TaskID, engine *harmonytask.T
261
261
for x , id := range ids {
262
262
indIDs [x ] = int64 (id )
263
263
}
264
- acceptables := map [harmonytask.TaskID ]bool {}
265
264
266
- for _ , t := range ids {
267
- acceptables [t ] = true
268
- }
269
-
270
- var ac []struct {
271
- TaskID harmonytask.TaskID `db:"indexing_task_id"`
272
- ShouldIndex bool `db:"should_index"`
273
- }
274
-
275
- err := i .db .Select (ctx , & ac , `select indexing_task_id, should_index from market_mk12_deal_pipeline where indexing_task_id = ANY ($1)` , indIDs )
276
- if err != nil {
277
- return nil , xerrors .Errorf ("getting pending indexing tasks: %w" , err )
278
- }
279
-
280
- for _ , t := range ac {
281
- if _ , ok := acceptables [t .TaskID ]; ! ok {
282
- continue
283
- }
284
-
285
- // Accept any task which should not be indexed as
286
- // it does not require storage access
287
- if ! t .ShouldIndex {
288
- return & t .TaskID , nil
289
- }
265
+ // Accept any task which should not be indexed as
266
+ // it does not require storage access
267
+ var id int64
268
+ err := i .db .QueryRow (ctx , `SELECT indexing_task_id
269
+ FROM market_mk12_deal_pipeline
270
+ WHERE should_index = FALSE AND
271
+ indexing_task_id = ANY ($1) ORDER BY indexing_task_id LIMIT 1` , indIDs ).Scan (& id )
272
+ if err == nil {
273
+ ret := harmonytask .TaskID (id )
274
+ return & ret , nil
275
+ } else if ! errors .Is (err , pgx .ErrNoRows ) {
276
+ return nil , xerrors .Errorf ("getting pending indexing task: %w" , err )
290
277
}
291
278
292
279
var tasks []struct {
@@ -314,15 +301,14 @@ func (i *IndexingTask) CanAccept(ids []harmonytask.TaskID, engine *harmonytask.T
314
301
return nil , xerrors .Errorf ("getting local storage: %w" , err )
315
302
}
316
303
317
- for _ , t := range tasks {
318
- if _ , ok := acceptables [ t . TaskID ]; ! ok {
319
- continue
320
- }
304
+ localStorageMap := make ( map [ string ] bool , len ( ls ))
305
+ for _ , l := range ls {
306
+ localStorageMap [ string ( l . ID )] = true
307
+ }
321
308
322
- for _ , l := range ls {
323
- if string (l .ID ) == t .StorageID {
324
- return & t .TaskID , nil
325
- }
309
+ for _ , t := range tasks {
310
+ if found , ok := localStorageMap [t .StorageID ]; ok && found {
311
+ return & t .TaskID , nil
326
312
}
327
313
}
328
314
0 commit comments