Skip to content

Commit 53c394f

Browse files
committed
perf(webapp): scope declarative schedule sync to the current environment
syncDeclarativeSchedules loaded every declarative schedule for the whole project across all environments, then re-fetched deletion candidates it already had in memory. Scope the load to the current environment, drop the redundant re-fetch, and select only the columns the reconcile uses. Also push projectId onto the schedule-limit count joins so it uses a project-scoped index instead of scanning the full TaskSchedule and RuntimeEnvironment tables. Follow-up to #4522, which batched the delete side.
1 parent 4569657 commit 53c394f

3 files changed

Lines changed: 25 additions & 12 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: improvement
4+
---
5+
6+
Make background worker registration cheaper for projects with many scheduled tasks by scoping declarative schedule reconciliation to the current environment and dropping redundant schedule lookups.

apps/webapp/app/v3/services/checkSchedule.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@ export class CheckScheduleService extends BaseService {
131131
projectId,
132132
active: true,
133133
environment: {
134+
projectId,
134135
type: {
135136
not: "DEVELOPMENT",
136137
},
137138
archivedAt: null,
138139
},
139140
taskSchedule: {
141+
projectId,
140142
active: true,
141143
},
142144
},

apps/webapp/app/v3/services/createBackgroundWorker.server.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,21 @@ export async function syncDeclarativeSchedules(
655655
where: {
656656
type: "DECLARATIVE",
657657
projectId: environment.projectId,
658+
instances: {
659+
some: {
660+
environmentId: environment.id,
661+
},
662+
},
658663
},
659-
include: {
660-
instances: true,
664+
select: {
665+
id: true,
666+
friendlyId: true,
667+
taskIdentifier: true,
668+
instances: {
669+
select: {
670+
environmentId: true,
671+
},
672+
},
661673
},
662674
});
663675

@@ -764,16 +776,9 @@ export async function syncDeclarativeSchedules(
764776

765777
//Delete instances for this environment
766778
//Delete schedules that have no instances left
767-
const potentiallyDeletableSchedules = await prisma.taskSchedule.findMany({
768-
where: {
769-
id: {
770-
in: boundedIn(Array.from(missingSchedules)),
771-
},
772-
},
773-
include: {
774-
instances: true,
775-
},
776-
});
779+
const potentiallyDeletableSchedules = existingDeclarativeSchedules.filter((schedule) =>
780+
missingSchedules.has(schedule.id)
781+
);
777782

778783
const scheduleIdsToDelete: string[] = [];
779784
const scheduleIdsToDetachFromEnvironment: string[] = [];

0 commit comments

Comments
 (0)