perf: Tasker performance improvements (#22395)

* perf: Tasker performance improvements

* Remove fields from expected tasker create call, test fix

* Fix the tests, needs validation
This commit is contained in:
Alex van Andel authored and GitHub committed 2025-07-11 10:09:24 -07:00
1 parent 8b3ff0b789
commit d7c9bd6ed8
7 files changed
+95 -53

No files matched your search

+23 -23
View File
@@ -1,4 +1,4 @@
import { type Prisma } from "@prisma/client";
import { Prisma } from "@prisma/client";
import db from "@calcom/prisma";
@@ -68,10 +68,6 @@ export class Task {
});
}
static async getAll() {
return db.task.findMany();
}
static async getFailed() {
return db.task.findMany({
where: whereMaxAttemptsReached,
@@ -155,24 +151,28 @@ export class Task {
});
}
static async cancelWithReference(referenceUid: string, type: TaskTypes) {
const task = await db.task.findFirst({
where: {
referenceUid,
type,
},
select: {
id: true,
},
});
if (!task) return null;
return await db.task.delete({
where: {
id: task.id,
},
});
static async cancelWithReference(referenceUid: string, type: TaskTypes): Promise<{ id: string } | null> {
// db.task.delete throws an error if the task does not exist, so we catch it and return null
try {
return await db.task.delete({
where: {
referenceUid_type: {
referenceUid,
type,
},
},
select: {
id: true,
},
});
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2025") {
// P2025 is the error code for "Record to delete does not exist"
console.warn(`Task with reference ${referenceUid} and type ${type} does not exist. No action taken.`);
return null;
}
throw error;
}
}
static async cleanup() {
@@ -34,10 +34,6 @@ export const ZTriggerFormSubmittedNoEventWebhookPayloadSchema = z.object({
id: z.string(),
name: z.string(),
teamId: z.number().nullable(),
fields: z
.array(z.object({ id: z.string(), label: z.string() }).passthrough())
.nullable()
.default([]),
}),
});