Skip to content

Conversation

@cstyan
Copy link
Contributor

@cstyan cstyan commented Dec 3, 2025

The metrics cache to calculate and expose build time metrics for templates currently calls GetTemplates, which returns all templates even if they are deleted. We can use the GetTemplatesWithFilter query to easily filter out deleted templates from the results, and thus not call GetTemplateAverageBuildTime for those deleted templates. Delete time for workspaces for non-deleted templates is still calculated.

…rkspaces

for non-deleted templates is still calculated)

Signed-off-by: Callum Styan <callumstyan@gmail.com>
templates, err := c.database.GetTemplates(ctx)
templates, err := c.database.GetTemplatesWithFilter(ctx, database.GetTemplatesWithFilterParams{
Deleted: false,
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to modify the UI that exercises this code path to include a deleted template and verify it's not included.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work as expected. I modified fetchTemplate in templates.go to also retrieve deleted templates. That function is used to populate the results for the Templates UI page. It takes a minute to update due to the timing intervals and processing, but once I'd built a workspace from a copy of an existing template + saw a build time for that copy template, I deleted the workspace and template copy.

We can see that the template is then still displayed in the Templates page but it's build time is Unknown, and if we click on that template we get an error since it's been deleted.

Screenshot 2025-12-03 at 3 49 29 PM Screenshot 2025-12-03 at 3 49 50 PM

@cstyan
Copy link
Contributor Author

cstyan commented Dec 3, 2025

Note that I didn't add a test in metricscache_test.go since it would have to be a full integration test (with a postgres instance) just to assert that we're not retrieving deleted templates. I can add one if there is a desire for one.

@cstyan cstyan merged commit 83dbf73 into main Dec 4, 2025
32 checks passed
@cstyan cstyan deleted the callum/template-metrics-deleted branch December 4, 2025 18:27
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants