From 089d1e62ade853468dc066331ce77b87bebc2df1 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Wed, 12 Aug 2026 13:43:24 +0100 Subject: [PATCH] perf(database): index WorkerDeployment on (environmentId, status, id) for the deployments list The deployments list query filters by status and paginates by id desc, but no index covered status, so Postgres seq-scanned the environment's deployments and discarded ~350 non-matching rows per row returned. Add (environmentId, status, id) so the status filter is index-satisfied and the scan is bounded to the page. --- .server-changes/worker-deployment-list-status-index.md | 6 ++++++ .../migration.sql | 1 + internal-packages/database/prisma/schema.prisma | 1 + 3 files changed, 8 insertions(+) create mode 100644 .server-changes/worker-deployment-list-status-index.md create mode 100644 internal-packages/database/prisma/migrations/20260812130000_add_worker_deployment_environment_id_status_id_index/migration.sql diff --git a/.server-changes/worker-deployment-list-status-index.md b/.server-changes/worker-deployment-list-status-index.md new file mode 100644 index 0000000000..e3fa07977b --- /dev/null +++ b/.server-changes/worker-deployment-list-status-index.md @@ -0,0 +1,6 @@ +--- +area: webapp +type: improvement +--- + +Loading the deployments list is now faster, especially when filtering by deployment status on projects with many deployments. diff --git a/internal-packages/database/prisma/migrations/20260812130000_add_worker_deployment_environment_id_status_id_index/migration.sql b/internal-packages/database/prisma/migrations/20260812130000_add_worker_deployment_environment_id_status_id_index/migration.sql new file mode 100644 index 0000000000..752528dd2a --- /dev/null +++ b/internal-packages/database/prisma/migrations/20260812130000_add_worker_deployment_environment_id_status_id_index/migration.sql @@ -0,0 +1 @@ +CREATE INDEX CONCURRENTLY IF NOT EXISTS "WorkerDeployment_environmentId_status_id_idx" ON "public"."WorkerDeployment"("environmentId", "status", "id"); diff --git a/internal-packages/database/prisma/schema.prisma b/internal-packages/database/prisma/schema.prisma index 868e02eb27..f705e40064 100644 --- a/internal-packages/database/prisma/schema.prisma +++ b/internal-packages/database/prisma/schema.prisma @@ -2214,6 +2214,7 @@ model WorkerDeployment { @@unique([environmentId, version]) @@index([commitSHA]) @@index([environmentId, createdAt]) + @@index([environmentId, status, id]) } enum WorkerDeploymentStatus {