Skip to content

Commit ae0ee62

Browse files
authored
fix(coderd/database): improve data exclusion in UpsertTemplateUsageStats (coder#12764)
The PostgreSQL query analyzer wasn't able to eliminate the agent stats without re-introducing this filter. Before: https://explain.dalibo.com/plan/21h7gb4f4bef391g After: https://explain.dalibo.com/plan/721ec1cccee91egc
1 parent f418ece commit ae0ee62

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

coderd/database/queries.sql.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/insights.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ WITH
599599
JOIN
600600
workspace_agent_stats AS was
601601
ON
602-
date_trunc('minute', was.created_at) = mb.minute_bucket
602+
was.created_at >= (SELECT t FROM latest_start)
603+
AND was.created_at < NOW()
604+
AND date_trunc('minute', was.created_at) = mb.minute_bucket
603605
AND was.template_id = mb.template_id
604606
AND was.user_id = mb.user_id
605607
AND was.connection_median_latency_ms >= 0

0 commit comments

Comments
 (0)