Skip to content

Commit 616945b

Browse files
committed
fix: attempt at improving worker actions query
1 parent 4f6c259 commit 616945b

3 files changed

Lines changed: 9 additions & 18 deletions

File tree

pkg/repository/sqlcv1/workers.sql

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,15 @@ GROUP BY "tenantId"
247247
;
248248

249249
-- name: GetWorkerActionsByWorkerId :many
250-
WITH inputs AS (
251-
SELECT UNNEST(@workerIds::UUID[]) AS "workerId"
252-
)
253-
254250
SELECT
255251
w."id" AS "workerId",
256252
a."actionId" AS actionId
257253
FROM "Worker" w
258-
JOIN inputs i ON w."id" = i."workerId"
259-
LEFT JOIN "_ActionToWorker" aw ON w.id = aw."B"
260-
LEFT JOIN "Action" a ON aw."A" = a.id
254+
JOIN "_ActionToWorker" aw ON w.id = aw."B"
255+
JOIN "Action" a ON aw."A" = a.id
261256
WHERE
262257
a."tenantId" = @tenantId::UUID
258+
AND w.id = ANY(@workerIds::UUID[])
263259
;
264260

265261
-- name: GetWorkerWorkflowsByWorkerId :many

pkg/repository/sqlcv1/workers.sql.go

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/repository/worker.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,12 @@ func (w *workerRepository) GetWorkerActionsByWorkerId(ctx context.Context, tenan
289289

290290
for _, record := range records {
291291
workerId := record.WorkerId.String()
292-
actionId := record.Actionid.String
293292

294293
if _, ok := workerIdToActionIds[workerId]; !ok {
295294
workerIdToActionIds[workerId] = make([]string, 0)
296295
}
297296

298-
workerIdToActionIds[workerId] = append(workerIdToActionIds[workerId], actionId)
297+
workerIdToActionIds[workerId] = append(workerIdToActionIds[workerId], record.Actionid)
299298
}
300299

301300
return workerIdToActionIds, nil

0 commit comments

Comments
 (0)