perf(webapp): drop archived branch environments from project env loads - #4595
Conversation
Several project pages loaded every RuntimeEnvironment for a project, including the potentially thousands of archived preview-branch environments that are never shown. On projects with heavy preview-branch usage this produced very large result sets and a rare multi-second tail on the environment lookup. Filter these environment relation loads to archivedAt: null (base environments never archive, so only archived branches are excluded) in ProjectPresenter and the concurrency, api keys, environment variables, and settings layout loaders. Also remove an unused environments select from DeploymentListPresenter.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (8)
🧰 Additional context used📓 Path-based instructions (6)**/*.{ts,tsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
{packages/core,apps/webapp}/**/*.{ts,tsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
apps/webapp/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)
Files:
apps/**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
apps/webapp/app/**/*.{ts,tsx}📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)
Files:
🧠 Learnings (31)📓 Common learnings📚 Learning: 2026-08-12T15:52:09.289ZApplied to files:
📚 Learning: 2026-04-01T13:27:35.831ZApplied to files:
📚 Learning: 2026-04-02T20:25:54.203ZApplied to files:
📚 Learning: 2026-02-11T16:50:14.167ZApplied to files:
📚 Learning: 2026-08-08T17:53:26.294ZApplied to files:
📚 Learning: 2026-07-26T20:37:56.220ZApplied to files:
📚 Learning: 2026-07-26T20:37:50.445ZApplied to files:
📚 Learning: 2026-04-02T19:18:34.807ZApplied to files:
📚 Learning: 2025-12-08T15:19:56.823ZApplied to files:
📚 Learning: 2026-07-26T20:37:55.391ZApplied to files:
📚 Learning: 2026-08-12T19:02:29.690ZApplied to files:
📚 Learning: 2026-02-03T18:27:40.429ZApplied to files:
📚 Learning: 2026-07-22T11:16:06.546ZApplied to files:
📚 Learning: 2026-02-11T16:37:32.429ZApplied to files:
📚 Learning: 2026-07-28T21:57:20.061ZApplied to files:
📚 Learning: 2026-03-22T13:26:12.060ZApplied to files:
📚 Learning: 2026-03-22T19:24:14.403ZApplied to files:
📚 Learning: 2026-05-18T08:21:27.694ZApplied to files:
📚 Learning: 2026-05-18T08:21:27.694ZApplied to files:
📚 Learning: 2026-06-13T19:53:13.759ZApplied to files:
📚 Learning: 2026-06-17T17:13:49.929ZApplied to files:
📚 Learning: 2026-06-23T13:04:21.413ZApplied to files:
📚 Learning: 2026-04-02T19:18:26.255ZApplied to files:
📚 Learning: 2026-05-12T21:04:00.184ZApplied to files:
📚 Learning: 2026-05-08T21:00:20.973ZApplied to files:
📚 Learning: 2026-06-25T18:21:55.847ZApplied to files:
📚 Learning: 2026-05-12T21:04:05.815ZApplied to files:
📚 Learning: 2026-06-25T18:21:51.905ZApplied to files:
📚 Learning: 2026-07-03T17:10:21.498ZApplied to files:
📚 Learning: 2026-06-25T18:21:54.729ZApplied to files:
🔇 Additional comments (1)
WalkthroughProject environment queries now exclude archived environments in the project presenter and project route loaders. The deployment list project query no longer selects environment metadata or associated user details. A changelog entry documents the project page loading change. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Extends the archivedAt: null filter to SelectBestEnvironmentPresenter's own project env loads so the project-root default redirect resolves consistently with the section routes and never lands on an archived (dead) preview branch.
The project _index route resolves the default environment via selectBestEnvironment from its own project env load; add archivedAt: null there too so every selectBestEnvironment caller is consistent and this loader gets the same bounding.
What
Several project pages loaded every
RuntimeEnvironmentrow for a project, including the archived preview-branch environments that are never shown in the UI. On a project with heavy preview-branch usage that means thousands of rows per load, producing a large result set and a rare multi-second tail on the environment lookup (~30s outlier observed via Insights onRuntimeEnvironmentprojectId lookups, fingerprintf2b3ecab…).The tail is dominated by the size of the result being parsed/transferred, not by the query plan (it already used
RuntimeEnvironment_projectId_idxwith no over-read). So the fix is to stop returning archived branch environments.Diagnosis correction
The ticket framed this as a "large
projectId INlist" and suggested bounding the IN list / cursor pagination. It's actually a Prisma nested relation load on a single-projectproject.findFirst, so theIN (...)holds one projectId and the trailingOFFSET $1is Prisma's relation-subquery artifact. The 4,644 rows in the observed execution were one project with ~4,644 environments (accumulated archived branches), not many projects.Change
Filter the
environmentsrelation load toarchivedAt: null(base envs never archive, so only archived preview branches are excluded):ProjectPresenter.server.tsorgs.$organizationSlug.projects.$projectParam.{concurrency,apikeys,environment-variables,settings}.ts(best-env resolvers)And remove an unused
environmentsselect fromDeploymentListPresenter.server.ts(it was selected but never read).loadProjectEnvironments(replay route) already filtersarchivedAt: null+ env type; this change follows that existing precedent.Evidence (isolated stack, seeded one project with 2,000 archived branch envs + 4 active)
EXPLAIN (ANALYZE)of the exact presenter sub-select:RuntimeEnvironment_projectId_idxarchivedAt IS NULL)Rows Removed by Filter: 2000)500x fewer rows to the client, which is what removes the parse-on-load tail. No new index needed.
typecheck --filter webappclean. UI verified: project layout, Deploys page, and the concurrency best-env redirect all render with the 2,000 archived branches present in the DB and zero console errors.Rollout / rollback
Straight deploy, no migration. Rollback is revert-only (read-path filter, no data change). Old and in-flight rows read correctly under both the old and new code.
Limitation
A project with thousands of active branches would still load them all; in practice active branches are few (branches are archived when their work merges). Hard-bounding active branches would be a larger change and is out of scope here.