Skip to content

Commit e7e543c

Browse files
committed
fix: index, multiple migrations
1 parent 824bf8c commit e7e543c

7 files changed

Lines changed: 49 additions & 29 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
-- +goose Up
22
-- +goose StatementBegin
3-
ALTER TABLE "Worker" ADD COLUMN "actionsHash" BYTEA;
3+
ALTER TABLE "Worker" ADD COLUMN "actionHash" BYTEA;
44
-- +goose StatementEnd
55

66
-- +goose Down
77
-- +goose StatementBegin
8-
ALTER TABLE "Worker" DROP COLUMN "actionsHash";
8+
ALTER TABLE "Worker" DROP COLUMN "actionHash";
99
-- +goose StatementEnd
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- +goose no transaction
2+
3+
-- +goose Up
4+
-- +goose StatementBegin
5+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "Worker_tenantId_actionHash_idx" ON "Worker" ("tenantId", "actionHash");
6+
-- +goose StatementEnd
7+
8+
-- +goose Down
9+
-- +goose StatementBegin
10+
DROP INDEX CONCURRENTLY IF EXISTS "Worker_tenantId_actionHash_idx";
11+
-- +goose StatementEnd

pkg/repository/sqlcv1/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/repository/sqlcv1/workers.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ INSERT INTO "Worker" (
435435
"languageVersion",
436436
"os",
437437
"runtimeExtra",
438-
"actionsHash"
438+
"actionHash"
439439
) VALUES (
440440
gen_random_uuid(),
441441
CURRENT_TIMESTAMP,
@@ -449,7 +449,7 @@ INSERT INTO "Worker" (
449449
sqlc.narg('languageVersion')::text,
450450
sqlc.narg('os')::text,
451451
sqlc.narg('runtimeExtra')::text,
452-
@actionsHash::bytea
452+
@actionHash::bytea
453453
) RETURNING *;
454454

455455
-- name: LinkServicesToWorker :exec

pkg/repository/sqlcv1/workers.sql.go

Lines changed: 21 additions & 21 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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type WorkerRepository interface {
8989
ListActiveSDKsPerTenant(ctx context.Context) (map[TenantIdSDKTuple]int64, error)
9090

9191
// GetWorkerActionsByWorkerId returns a list of actions for a worker
92-
GetWorkerActionsByWorkerId(ctx context.Context, tenantId uuid.UUID, workerId []uuid.UUID) (map[string][]string, error)
92+
GetWorkerActionsForWorkers(ctx context.Context, tenantId uuid.UUID, workers []sqlcv1.Worker) (map[string][]string, error)
9393

9494
// GetWorkerWorkflowsByWorkerId returns a list of workflows for a worker
9595
GetWorkerWorkflowsByWorkerId(ctx context.Context, tenantId uuid.UUID, workerId uuid.UUID) ([]*sqlcv1.Workflow, error)
@@ -276,7 +276,13 @@ func (w *workerRepository) CountActiveWorkersPerTenant(ctx context.Context) (map
276276
return tenantToWorkers, nil
277277
}
278278

279-
func (w *workerRepository) GetWorkerActionsByWorkerId(ctx context.Context, tenantId uuid.UUID, workerIds []uuid.UUID) (map[string][]string, error) {
279+
func (w *workerRepository) GetWorkerActionsForWorkers(ctx context.Context, tenantId uuid.UUID, workers []sqlcv1.Worker) (map[string][]string, error) {
280+
actionHashToWorkerId := make(map[uuid.UUID][]byte)
281+
282+
for _, worker := range workers {
283+
actionHashToWorkerId[worker.ID] = worker.ActionsHash
284+
}
285+
280286
records, err := w.queries.GetWorkerActionsByWorkerId(ctx, w.pool, sqlcv1.GetWorkerActionsByWorkerIdParams{
281287
Workerids: workerIds,
282288
Tenantid: tenantId,

sql/schema/v0.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ CREATE TABLE "Worker" (
864864
"runtimeExtra" TEXT,
865865
"sdkVersion" TEXT,
866866
"durableTaskDispatcherId" UUID,
867-
"actionsHash" BYTEA,
867+
"actionHash" BYTEA,
868868

869869
CONSTRAINT "Worker_pkey" PRIMARY KEY ("id")
870870
);
@@ -1442,6 +1442,9 @@ CREATE UNIQUE INDEX "Worker_webhookId_key" ON "Worker" ("webhookId" ASC);
14421442

14431443
CREATE INDEX "Worker_tenantId_lastHeartbeatAt_idx" ON "Worker" ("tenantId", "lastHeartbeatAt");
14441444

1445+
-- CreateIndex
1446+
CREATE INDEX "Worker_tenantId_actionHash_idx" ON "Worker" ("tenantId", "actionHash");
1447+
14451448
-- CreateIndex
14461449
CREATE INDEX "WorkerAssignEvent_workerId_id_idx" ON "WorkerAssignEvent" ("workerId" ASC, "id" ASC);
14471450

0 commit comments

Comments
 (0)