Commit 44bfb67
committed
perf(webapp): speed up EnvironmentVariableValue lookups
The /api/v1/projects/:projectRef/envvars/:slug/:name route calls
`getEnvironmentWithRedactedSecrets`, which runs a Prisma findMany on
EnvironmentVariableValue filtered by environmentId + isSecret. Two
issues compound:
1. The only existing indexes are the primary key and a unique on
(variableId, environmentId), so environmentId is never the leading
column. Postgres falls back to a Parallel Seq Scan over the whole
table for what is, in practice, a handful of rows per environment.
2. The repository was running this read on the writer client.
Two changes:
- Add a btree index on EnvironmentVariableValue(environmentId) so the
planner switches to an index scan and the CPU + buffer-pin
(LWLock:BufferContent) cost from concurrent calls disappears.
- Route this one findMany through the read replica via a new
`replicaClient` constructor param on the repository (defaulting to
$replica, mirroring how prismaClient defaults to prisma). Writes
and read-after-write methods stay on the primary.
The composite (variableId, environmentId) unique stays in place; the
new index is purely additive.1 parent 6b46a34 commit 44bfb67
4 files changed
Lines changed: 16 additions & 3 deletions
File tree
- .server-changes
- apps/webapp/app/v3/environmentVariables
- internal-packages/database/prisma
- migrations/20260520120000_add_environment_variable_value_environment_id_idx
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| |||
582 | 585 | | |
583 | 586 | | |
584 | 587 | | |
585 | | - | |
| 588 | + | |
586 | 589 | | |
587 | 590 | | |
588 | 591 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2020 | 2020 | | |
2021 | 2021 | | |
2022 | 2022 | | |
| 2023 | + | |
2023 | 2024 | | |
2024 | 2025 | | |
2025 | 2026 | | |
| |||
0 commit comments