perf(webapp): look up environments by indexed organization column - #4477
Draft
claude[bot] wants to merge 1 commit into
Draft
perf(webapp): look up environments by indexed organization column#4477claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B6byUe71HjFpnGAsicw7Hy
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested via Slack thread
Before: the metric endpoint built its environment field mappings by asking for every environment whose project belongs to the organization. Filtering through the project relation forces a join against the projects table, and it happened on every single request.
After: the same lookup filters on the environment's own organization column, which is indexed. It returns exactly the same set of environments with less work per request. This endpoint is polled frequently by the dashboard charts, so it runs often and the saving adds up.
How
RuntimeEnvironmentalready carries its own non-nullableorganizationIdcolumn with an index on it, and that column is always populated with the same organization as the environment's project — every creation path (project setup, per-member development environments, preview branches) sets both from the same source, and nothing reassigns a project between organizations. Sowhere: { project: { organizationId } }andwhere: { organizationId }select identical rows.The change swaps one for the other. No extra predicates were added — neither the old nor the new filter applies any archived/deleted condition, so behaviour is unchanged. The neighbouring project lookup already filters on its column directly and was left alone.
Testing
Webapp typecheck passes. The change is a one-line filter swap on a read query with no behavioural difference: both filters resolve to the same set of environments, and the surrounding mapping code is untouched.
Changelog
Dashboard charts load with less database work behind the scenes.
Screenshots
No UI change.