Skip to content

Commit fa20901

Browse files
committed
chore: merge main into feat/agent-storybook-gallery (post-squash of #4525)
2 parents 6de38dc + 0b750d0 commit fa20901

5 files changed

Lines changed: 43 additions & 13 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.
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+
Speed up setting and importing environment variables for projects with many variables.

apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { AuthenticatedEnvironment } from "@trigger.dev/core/v3/auth/environment";
2-
import { Prisma, type PrismaClient, type RuntimeEnvironmentType } from "@trigger.dev/database";
2+
import {
3+
boundedIn,
4+
Prisma,
5+
type PrismaClient,
6+
type RuntimeEnvironmentType,
7+
} from "@trigger.dev/database";
38
import { z } from "zod";
49
import { environmentFullTitle } from "~/components/environments/EnvironmentLabel";
510
import { $replica, $transaction, prisma, type PrismaReplicaClient } from "~/db.server";
@@ -66,9 +71,15 @@ export class EnvironmentVariablesRepository implements Repository {
6671
},
6772
},
6873
environmentVariables: {
74+
where: {
75+
key: { in: boundedIn(options.variables.map((v) => v.key)) },
76+
},
6977
select: {
7078
key: true,
7179
values: {
80+
where: {
81+
environmentId: { in: boundedIn(options.environmentIds) },
82+
},
7283
select: {
7384
environment: {
7485
select: { id: true, type: true },

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)