Skip to content

perf(webapp): look up environments by indexed organization column - #4477

Draft
claude[bot] wants to merge 1 commit into
mainfrom
claude/narrow-metric-environment-lookup
Draft

perf(webapp): look up environments by indexed organization column#4477
claude[bot] wants to merge 1 commit into
mainfrom
claude/narrow-metric-environment-lookup

Conversation

@claude

@claude claude Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

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

RuntimeEnvironment already carries its own non-nullable organizationId column 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. So where: { project: { organizationId } } and where: { 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.

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
@changeset-bot

changeset-bot Bot commented Aug 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 86e4c08

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

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.

1 participant