Skip to content

Commit afe280c

Browse files
committed
perf(database): index BatchTaskRun on (runtimeEnvironmentId, createdAt, id) for the batches list
The batches list page orders by createdAt DESC, id DESC filtered by environment and a created-at window, but the only matching index was (runtimeEnvironmentId, id), which cannot satisfy the createdAt ordering. On environments with many batches the query fell back to a full table scan and in-memory sort, which could run long enough to hit the statement timeout. Adds (runtimeEnvironmentId, createdAt DESC, id DESC) so the query reads straight from the index in order. Created with CONCURRENTLY IF NOT EXISTS, so it takes no table lock and is a no-op if already present.
1 parent 722e240 commit afe280c

3 files changed

Lines changed: 9 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: fix
4+
---
5+
6+
Speed up the Batches list page for environments with a large number of batches, which could previously time out while loading.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- CreateIndex
2+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "BatchTaskRun_runtimeEnvironmentId_createdAt_id_idx" ON "public"."BatchTaskRun"("runtimeEnvironmentId", "createdAt" DESC, "id" DESC);

internal-packages/database/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,7 @@ model BatchTaskRun {
19351935
@@index([dependentTaskAttemptId])
19361936
// This is for the batch list dashboard page
19371937
@@index([runtimeEnvironmentId, id(sort: Desc)])
1938+
@@index([runtimeEnvironmentId, createdAt(sort: Desc), id(sort: Desc)])
19381939
}
19391940

19401941
enum BatchTaskRunStatus {

0 commit comments

Comments
 (0)