diff --git a/.server-changes/scope-env-var-create-precheck.md b/.server-changes/scope-env-var-create-precheck.md new file mode 100644 index 0000000000..550215f568 --- /dev/null +++ b/.server-changes/scope-env-var-create-precheck.md @@ -0,0 +1,6 @@ +--- +area: webapp +type: improvement +--- + +Speed up setting and importing environment variables for projects with many variables. diff --git a/apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts b/apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts index 4570b46b19..02fe998fca 100644 --- a/apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts +++ b/apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts @@ -1,5 +1,10 @@ import type { AuthenticatedEnvironment } from "@trigger.dev/core/v3/auth/environment"; -import { Prisma, type PrismaClient, type RuntimeEnvironmentType } from "@trigger.dev/database"; +import { + boundedIn, + Prisma, + type PrismaClient, + type RuntimeEnvironmentType, +} from "@trigger.dev/database"; import { z } from "zod"; import { environmentFullTitle } from "~/components/environments/EnvironmentLabel"; import { $replica, $transaction, prisma, type PrismaReplicaClient } from "~/db.server"; @@ -66,9 +71,15 @@ export class EnvironmentVariablesRepository implements Repository { }, }, environmentVariables: { + where: { + key: { in: boundedIn(options.variables.map((v) => v.key)) }, + }, select: { key: true, values: { + where: { + environmentId: { in: boundedIn(options.environmentIds) }, + }, select: { environment: { select: { id: true, type: true },