Skip to content

Commit 76a15fd

Browse files
committed
The run filter for tasks query was very slow if you had a lot of synced tasks
1 parent 824a620 commit 76a15fd

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

apps/webapp/app/presenters/v3/RunListPresenter.server.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Prisma, TaskRunStatus } from "@trigger.dev/database";
1+
import { Prisma, TaskRunStatus, TaskTriggerSource } from "@trigger.dev/database";
22
import parse from "parse-duration";
33
import { Direction } from "~/components/runs/RunStatuses";
44
import { FINISHED_STATUSES } from "~/components/runs/v3/TaskRunStatus";
@@ -94,12 +94,16 @@ export class RunListPresenter extends BasePresenter {
9494
});
9595

9696
//get all possible tasks
97-
const possibleTasksAsync = this._replica.backgroundWorkerTask.findMany({
98-
distinct: ["slug"],
99-
where: {
100-
projectId: project.id,
101-
},
102-
});
97+
const possibleTasksAsync = this._replica.$queryRaw<
98+
{
99+
slug: string;
100+
triggerSource: TaskTriggerSource
101+
}[]
102+
>`
103+
SELECT DISTINCT(slug), "triggerSource"
104+
FROM ${sqlDatabaseSchema}."BackgroundWorkerTask"
105+
WHERE "projectId" = ${project.id}
106+
ORDER BY slug ASC;`;
103107

104108
//get possible bulk actions
105109
const bulkActionsAsync = this._replica.bulkActionGroup.findMany({

0 commit comments

Comments
 (0)