Skip to content

Commit

Permalink
Added a db index to make the schedule list page faster
Browse files Browse the repository at this point in the history
There was a slow query to get the latest run for a list of schedules
  • Loading branch information
matt-aitken committed Nov 6, 2024
1 parent e422fb5 commit f099668
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- CreateIndex
CREATE INDEX CONCURRENTLY IF NOT EXISTS "TaskRun_scheduleId_createdAt_idx" ON "TaskRun"("scheduleId", "createdAt" DESC);
2 changes: 2 additions & 0 deletions internal-packages/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,8 @@ model TaskRun {
@@index([parentSpanId])
// Finding completed runs
@@index([completedAt])
// Schedule list page
@@index([scheduleId, createdAt(sort: Desc)])
}

enum TaskRunStatus {
Expand Down
11 changes: 11 additions & 0 deletions references/hello-world/src/trigger/schedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { schedules } from "@trigger.dev/sdk/v3";

export const simpleSchedule = schedules.task({
id: "simple-schedule",
cron: "0 0 * * *",
run: async (payload, { ctx }) => {
return {
message: "Hello, world!",
};
},
});

0 comments on commit f099668

Please sign in to comment.