Skip to content

Commit f099668

Browse files
committed
Added a db index to make the schedule list page faster
There was a slow query to get the latest run for a list of schedules
1 parent e422fb5 commit f099668

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- CreateIndex
2+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "TaskRun_scheduleId_createdAt_idx" ON "TaskRun"("scheduleId", "createdAt" DESC);

internal-packages/database/prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,8 @@ model TaskRun {
17991799
@@index([parentSpanId])
18001800
// Finding completed runs
18011801
@@index([completedAt])
1802+
// Schedule list page
1803+
@@index([scheduleId, createdAt(sort: Desc)])
18021804
}
18031805

18041806
enum TaskRunStatus {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { schedules } from "@trigger.dev/sdk/v3";
2+
3+
export const simpleSchedule = schedules.task({
4+
id: "simple-schedule",
5+
cron: "0 0 * * *",
6+
run: async (payload, { ctx }) => {
7+
return {
8+
message: "Hello, world!",
9+
};
10+
},
11+
});

0 commit comments

Comments
 (0)