Repository navigation
Conversation
This was referenced Nov 2, 2026
kylecarbs
marked this pull request as ready for review
November 3, 2026 22:11
GetTemplateAverageBuildTime runs once per template on every metrics cache refresh and scanned every workspace build because nothing indexed workspace_builds.template_version_id. Index (template_version_id, created_at DESC) and read the newest 100 successful builds per version before taking the newest 100 overall. The newest 100 of a template are always within each version's newest 100, so the result is unchanged. Adds a regression test for the success filter. Generated by Coder Agents.
kylecarbs
force-pushed
the
perf/db-template-avg-build-time
branch
from
November 9, 2026 21:28
8edcf1e to
b5b4dcd
Compare
This branch has not been deployed
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.
GetTemplateAverageBuildTimeruns once per template on every metrics cache refresh. Nothing indexedworkspace_builds.template_version_id, so each call scanned every workspace build. At 300 templates and 2.1M builds that came to about 42 s of database time per refresh.Adds a
workspace_builds (template_version_id, created_at DESC)index. The query now reads the newest 100 successful builds per version, then takes the newest 100 overall. A template's newest 100 builds are always within each version's newest 100, so the result is the same.The rewrite is needed: with only the index, the large template got slower (145 to 407 ms). Results were identical for all 300 seeded templates plus a missing one, and for 40 templates with randomized durations, cancels, failures, and transitions. A new
TestGetTemplateAverageBuildTimefails if the success filter moves after the per-version limit.NOTE: This migration builds an index on
workspace_builds(96 MB at 2.1M rows), which blocks writes to that table during the upgrade. Neither column changes after insert, so updates stay eligible for HOT.Depends on #31623.
Generated by Coder Agents on behalf of @kylecarbs.