From eefe0a378dd45279eb439190717aa4d0902da2a3 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Thu, 13 Aug 2026 16:31:51 +0100 Subject: [PATCH] perf(webapp): bound environment loads in the env layout and batches list (#4606) ## Summary Follow-up to #4595. Dashboard pages under an environment loaded every environment in the project on each page just to resolve the one named in the URL. On projects with many preview branches that meant reading hundreds of (mostly archived) rows on every page load. ## Fix The environment-scoped layout loader now scopes its lookup to the slug in the URL (`where: { slug: envParam }`), resolving the current environment through the `projectId, slug` composite index instead of loading the whole project. Archived branches stay viewable by slug. `BatchListPresenter` is bounded to the current environment, since every batch in that list already belongs to it. Verified on a project seeded with 2,000 archived branch environments: the layout lookup drops from all environments to one, and both a normal environment page and an archived branch page render correctly. --- .server-changes/bound-env-layout-environment-load.md | 6 ++++++ apps/webapp/app/presenters/v3/BatchListPresenter.server.ts | 1 + .../route.tsx | 1 + 3 files changed, 8 insertions(+) create mode 100644 .server-changes/bound-env-layout-environment-load.md diff --git a/.server-changes/bound-env-layout-environment-load.md b/.server-changes/bound-env-layout-environment-load.md new file mode 100644 index 000000000..5c658a99e --- /dev/null +++ b/.server-changes/bound-env-layout-environment-load.md @@ -0,0 +1,6 @@ +--- +area: webapp +type: improvement +--- + +Dashboard pages load faster on projects with many preview branches by no longer loading every environment on each page. diff --git a/apps/webapp/app/presenters/v3/BatchListPresenter.server.ts b/apps/webapp/app/presenters/v3/BatchListPresenter.server.ts index 6de786159..4596b08f0 100644 --- a/apps/webapp/app/presenters/v3/BatchListPresenter.server.ts +++ b/apps/webapp/app/presenters/v3/BatchListPresenter.server.ts @@ -200,6 +200,7 @@ export class BatchListPresenter extends BasePresenter { select: { id: true, environments: { + where: { id: environmentId }, select: { id: true, type: true, diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam/route.tsx index 1af9c9d9c..50ac6f89f 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam/route.tsx @@ -40,6 +40,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => { externalRef: true, organization: { select: { id: true, featureFlags: true } }, environments: { + where: { slug: envParam }, select: { id: true, type: true,