Skip to content

perf(webapp): paginate the environment variables settings page - #4597

Merged
ericallam merged 1 commit into
mainfrom
feature/tri-13185-perfcontrol-plane-env-var-resolution-fetches-18k
Aug 12, 2026
Merged

perf(webapp): paginate the environment variables settings page#4597
ericallam merged 1 commit into
mainfrom
feature/tri-13185-perfcontrol-plane-env-var-resolution-fetches-18k

Conversation

@ericallam

@ericallam ericallam commented Aug 12, 2026

Copy link
Copy Markdown
Member

What

The environment variables settings page loaded every variable in the project in one shot, with a nested values read plus a valueReference (SecretReference) sub-load that was selected but never read. For a project with many variables this pulled variables × environments value rows (~18k for large projects) on every page load, plus a matching ~18k-row SecretReference IN query.

This paginates the presenter by variable key and removes the dead include.

  • Remove the never-read valueReference: { select: { key } } include → the SecretReference query is gone entirely.
  • Paginate the parent variable query: count + orderBy key + skip/take, page size 50 → the value read is bounded to pageSize × environments per page.
  • Scope the count and the page to variables that have a value in a displayed environment (values: { some: { environmentId: { in } } }), so totalCount/totalPages and the skip/take window match what actually renders (no phantom empty pages from variables that live only in archived branches or another member's dev env).
  • Display order comes from the DB orderBy: { key: "asc" } — the presenter no longer re-sorts each page with localeCompare, which under pagination could disagree with the DB collation at page boundaries.
  • The secret-value lookup (SecretStore keys) and the updater lookup (user by id) are now scoped to the current page instead of the whole project.
  • Search moves server-side (variable key, case-insensitive) and drives both the count and the page; the UI gains standard pagination controls.

Why

The two correlated ~18k-row control-plane queries flagged in the ticket come from this settings-page presenter, not from any hot path. Both are index-covered (rows_read == rows_returned); the issue is the sheer volume fetched in one burst. Bounding it per page removes the burst.

Evidence

Measured on an isolated stack with a seeded project of 1000 variables × 3 environments (3000 value rows), using Prisma's emitted-SQL log:

SecretReference query value rows fetched
before 1 3000
after 0 150 (page 1) + one count

EXPLAIN on Prisma's verbatim statements (index confirmed via enable_seqscan=off; the local table is too small for the planner to choose them by default):

  • count (WHERE projectId AND EXISTS(values in displayed envs)) → Hash Join: Index Scan on EnvironmentVariable_pkey + Bitmap Index Scan on EnvironmentVariableValue_environmentId_idx
  • paginated parent (WHERE projectId AND EXISTS(...) ORDER BY key LIMIT/OFFSET) → Nested Loop Semi Join: Index Scan on EnvironmentVariable_projectId_key_key (no Sort node) driving an Index-Only Scan on EnvironmentVariableValue_variableId_environmentId_key
  • nested values (variableId = ANY … AND environmentId = ANY …) → index scan on EnvironmentVariableValue_environmentId_idx
  • SecretStore keys (key = ANY …) → index scan on SecretStore_key_idx

No new index required. Verified in the browser on the seeded project: 20 pages, page navigation, server-side search (matches across all pages), last page renders, no app console errors. typecheck, oxlint, oxfmt all clean.

Behavior change

The previous client-side search matched variable name and value (and environment type / branch name). Values are encrypted at rest and resolved separately, so they cannot be searched server-side under pagination. Search is now variable-name only, server-side, case-insensitive. Projects with fewer than one page of variables see no pagination bar and no visible change.

Rollout / rollback

Pure read-path change on a dashboard loader, no schema or data migration. Rollback is a straight revert.

Screenshots

01-page1 02-search-single

@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4f69315

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ba8596c4-5473-4f57-bb2c-7dab3ccf2b72

📥 Commits

Reviewing files that changed from the base of the PR and between 622d053 and 4f69315.

📒 Files selected for processing (1)
  • apps/webapp/app/presenters/v3/EnvironmentVariablesPresenter.server.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/webapp/app/presenters/v3/EnvironmentVariablesPresenter.server.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (7)
  • GitHub Check: obsmap / 🧪 Unit Tests: Observability Map
  • GitHub Check: runops-guard / runops-guard
  • GitHub Check: report
  • GitHub Check: code-quality / code-quality
  • GitHub Check: audit
  • GitHub Check: audit
  • GitHub Check: Analyze (javascript-typescript)

Walkthrough

Environment-variable loading now supports server-side search and pagination. The presenter filters keys case-insensitively, sorts results by key, clamps the requested page, and returns pagination metadata. The route validates query parameters and passes them to the presenter. The page uses server-filtered results, resets pagination when searching, preserves search controls for empty matches, and displays pagination controls for multiple pages. A changelog entry documents the change.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: paginating the environment variables settings page.
Description check ✅ Passed The description explains the motivation, implementation, behavior changes, testing evidence, rollout plan, and screenshots in sufficient detail.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/tri-13185-perfcontrol-plane-env-var-resolution-fetches-18k

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ericallam
ericallam marked this pull request as ready for review August 12, 2026 21:53
devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feature/tri-13185-perfcontrol-plane-env-var-resolution-fetches-18k branch from 6572847 to 622d053 Compare August 12, 2026 22:06
devin-ai-integration[bot]

This comment was marked as resolved.

The env-var settings page loaded every variable in the project with a
nested values read plus an unused valueReference (SecretReference) sub-load,
so a project with many variables pulled variables x environments rows (~18k
for large projects) in one burst on each page load.

Paginate the presenter by variable key (count + orderBy key + skip/take,
page size 50) and drop the never-read valueReference include. This bounds
the value read to pageSize x environments per page, removes the
SecretReference query entirely, and scopes the secret-value and updater
lookups to the current page. Search moves server-side (key, case-insensitive)
and the page gains pagination controls.

All queries are index-backed: the (projectId, key) unique serves both the
count and the ordered pagination (no sort), and the value/secret/user reads
use existing indexes with page-scoped IN lists.
@ericallam
ericallam force-pushed the feature/tri-13185-perfcontrol-plane-env-var-resolution-fetches-18k branch from 622d053 to 4f69315 Compare August 12, 2026 22:29
@ericallam
ericallam enabled auto-merge (squash) August 12, 2026 22:44
@ericallam
ericallam merged commit c6ef5f3 into main Aug 12, 2026
40 checks passed
@ericallam
ericallam deleted the feature/tri-13185-perfcontrol-plane-env-var-resolution-fetches-18k branch August 12, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants