From 83dbf73ddeb4d54cc22aa9010b7db133c98bbef7 Mon Sep 17 00:00:00 2001 From: Callum Styan Date: Thu, 4 Dec 2025 10:27:56 -0800 Subject: [PATCH] perf: don't calculate build times for deleted templates (#21072) 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. Signed-off-by: Callum Styan --- coderd/metricscache/metricscache.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/coderd/metricscache/metricscache.go b/coderd/metricscache/metricscache.go index 837508628d..1302f181d1 100644 --- a/coderd/metricscache/metricscache.go +++ b/coderd/metricscache/metricscache.go @@ -87,7 +87,9 @@ func (c *Cache) refreshTemplateBuildTimes(ctx context.Context) error { //nolint:gocritic // This is a system service. ctx = dbauthz.AsSystemRestricted(ctx) - templates, err := c.database.GetTemplates(ctx) + templates, err := c.database.GetTemplatesWithFilter(ctx, database.GetTemplatesWithFilterParams{ + Deleted: false, + }) if err != nil { return err }