perf: don't calculate build times for deleted templates#21072
Conversation
…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, | ||
| }) |
There was a problem hiding this comment.
Would be good to modify the UI that exercises this code path to include a deleted template and verify it's not included.
There was a problem hiding this comment.
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.
|
Note that I didn't add a test in |
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 theGetTemplatesWithFilterquery to easily filter out deleted templates from the results, and thus not callGetTemplateAverageBuildTimefor those deleted templates. Delete time for workspaces for non-deleted templates is still calculated.