Skip to content

Commit 26cdedd

Browse files
authored
perf(webapp): scope env var create pre-check to submitted keys (#4579)
## Summary Setting or importing environment variables ran a conflict pre-check that loaded every variable in the project and every value across all of its environments, only to decide whether the submitted keys already had a value in the target environments. On projects with many variables and environments that meant reading tens of thousands of rows on each create/import call. This scopes the pre-check to the submitted keys and target environments, so it reads only the rows it actually inspects (submitted keys × target envs), wrapped in `boundedIn` to keep the prepared-statement cache stable. Same conflict detection, a handful of rows instead of the whole project's env-var values.
1 parent 9a3bee0 commit 26cdedd

2 files changed

Lines changed: 18 additions & 1 deletion

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+
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 },

0 commit comments

Comments
 (0)