Skip to content

Show template average build #4545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify sql query
  • Loading branch information
iskhakovt committed Sep 12, 2022
commit 151a76bdd738236ceb1dd8f94d0323b629130f83
3 changes: 3 additions & 0 deletions coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 24 additions & 19 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions coderd/database/queries/templates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ RETURNING
*;

-- name: GetTemplatesAverageBuildTime :many
-- Computes average build time for every template.
-- Only considers last moving_average_size successful builds between start_ts and end_ts.
-- If a template does not have at least min_completed_job_count such builds, it gets skipped.
WITH query_with_all_job_count AS (SELECT
DISTINCT t.id,
AVG(pj.exec_time_sec)
Expand All @@ -122,7 +125,7 @@ FROM
active_version_id
FROM
templates) AS t
LEFT JOIN
INNER JOIN
(SELECT
workspace_id,
template_version_id,
Expand All @@ -133,7 +136,7 @@ LEFT JOIN
wb
ON
t.id = wb.workspace_id AND t.active_version_id = wb.template_version_id
LEFT JOIN
INNER JOIN
(SELECT
id,
completed_at,
Expand All @@ -155,6 +158,5 @@ SELECT
FROM
query_with_all_job_count
WHERE
avg_build_time_sec IS NOT NULL AND
job_count >= GREATEST(@min_completed_job_count::integer, 1)
job_count >= @min_completed_job_count::integer
;