perf(coderd): simplify insights queries to speed them up (#9299)

This commit is contained in:
Mathias Fredriksson
2023-08-24 13:52:20 +03:00
committed by GitHub
parent 6b69abfec7
commit d00817ea4a
3 changed files with 0 additions and 31 deletions

View File

@ -1499,12 +1499,6 @@ WITH ts AS (
wa.agent_id = was.agent_id
AND wa.slug = was.slug_or_port
)
WHERE
-- We already handle timeframe in the join, but we use an additional
-- check against a static timeframe to help speed up the query.
(was.session_started_at >= $1 AND was.session_started_at < $2)
OR (was.session_ended_at > $1 AND was.session_ended_at < $2)
OR (was.session_started_at < $1 AND was.session_ended_at >= $2)
GROUP BY ts.from_, ts.to_, ts.seconds, w.template_id, was.user_id, was.agent_id, was.access_method, was.slug_or_port, wa.display_name, wa.icon, wa.slug
)
@ -1706,11 +1700,6 @@ WITH ts AS (
AND was.connection_count > 0
AND CASE WHEN COALESCE(array_length($3::uuid[], 1), 0) > 0 THEN was.template_id = ANY($3::uuid[]) ELSE TRUE END
)
WHERE
-- We already handle created_at in the join, but we use an additional
-- check against a static timeframe to help speed up the query.
was.created_at >= $1
AND was.created_at < $2
GROUP BY ts.from_, ts.to_, ts.seconds, was.user_id
), template_ids AS (
SELECT array_agg(DISTINCT template_id) AS ids