Skip to content

Commit f7ac0f4

Browse files
committed
perf(webapp,database): index the newest-task-version lookup
Schedule validation seeks (projectId, slug) and then sorts every matching row by createdAt to return one. A project gains a row per task per deploy, so the sort grows with project age. Index the sort key so Postgres scans backward and stops at the first row, and select only the field the check reads.
1 parent 771937a commit f7ac0f4

4 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: improvement
4+
---
5+
6+
Creating or updating a schedule, and deploying a project with declarative schedules, is faster in long-lived projects with many deploys.

apps/webapp/app/v3/services/checkSchedule.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export class CheckScheduleService extends BaseService {
4545
slug: schedule.taskIdentifier,
4646
projectId: projectId,
4747
},
48+
select: {
49+
triggerSource: true,
50+
},
4851
orderBy: {
4952
createdAt: "desc",
5053
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "BackgroundWorkerTask_projectId_slug_createdAt_idx" ON "public"."BackgroundWorkerTask"("projectId", "slug", "createdAt");

internal-packages/database/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ model BackgroundWorkerTask {
752752
@@unique([workerId, slug])
753753
// Quick lookup of task identifiers
754754
@@index([projectId, slug])
755+
@@index([projectId, slug, createdAt])
755756
@@index([runtimeEnvironmentId, projectId])
756757
@@index([runtimeEnvironmentId, slug, triggerSource])
757758
}

0 commit comments

Comments
 (0)