Skip to content

Commit 4881243

Browse files
committed
use should_index in query
1 parent ddef306 commit 4881243

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

tasks/indexing/task_indexing.go

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -261,32 +261,19 @@ func (i *IndexingTask) CanAccept(ids []harmonytask.TaskID, engine *harmonytask.T
261261
for x, id := range ids {
262262
indIDs[x] = int64(id)
263263
}
264-
acceptables := map[harmonytask.TaskID]bool{}
265264

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)
290277
}
291278

292279
var tasks []struct {
@@ -314,15 +301,14 @@ func (i *IndexingTask) CanAccept(ids []harmonytask.TaskID, engine *harmonytask.T
314301
return nil, xerrors.Errorf("getting local storage: %w", err)
315302
}
316303

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+
}
321308

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
326312
}
327313
}
328314

0 commit comments

Comments
 (0)