From 86e4c08356647d3b5fba7624196f46ec7d591f4b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 2 Aug 2026 15:24:24 +0000 Subject: [PATCH] perf(webapp): look up environments by indexed organization column The metric endpoint built its environment field mappings with a `where: { project: { organizationId } }` filter, which joins through the projects table on every request. RuntimeEnvironment has its own non-null, indexed organizationId column that is always set to the same organization as the environment's project, so filter on it directly instead. Returns the same set of environments with less work per request. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01B6byUe71HjFpnGAsicw7Hy --- .server-changes/narrow-metric-environment-lookup.md | 6 ++++++ apps/webapp/app/services/queryService.server.ts | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .server-changes/narrow-metric-environment-lookup.md diff --git a/.server-changes/narrow-metric-environment-lookup.md b/.server-changes/narrow-metric-environment-lookup.md new file mode 100644 index 00000000000..1d6326e72c8 --- /dev/null +++ b/.server-changes/narrow-metric-environment-lookup.md @@ -0,0 +1,6 @@ +--- +area: webapp +type: improvement +--- + +Dashboard charts load with less database work behind the scenes diff --git a/apps/webapp/app/services/queryService.server.ts b/apps/webapp/app/services/queryService.server.ts index bcceca25bbb..a14a2415509 100644 --- a/apps/webapp/app/services/queryService.server.ts +++ b/apps/webapp/app/services/queryService.server.ts @@ -359,7 +359,8 @@ export async function executeQuery( }); const environments = await prisma.runtimeEnvironment.findMany({ - where: { project: { organizationId } }, + // Same set as filtering through `project`, but hits the indexed column without the join. + where: { organizationId }, select: { id: true, slug: true }, });