File tree Expand file tree Collapse file tree 1 file changed +18
-15
lines changed Expand file tree Collapse file tree 1 file changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -108,9 +108,12 @@ RETURNING
108
108
109
109
-- name: GetTemplatesAverageBuildTime :many
110
110
WITH query_with_all_job_count AS (SELECT
111
- DISTINCT t .id ,
111
+ DISTINCT t .id ,
112
112
AVG (pj .exec_time_sec )
113
- OVER(PARTITION BY t .id ORDER BY pj .completed_at ROWS BETWEEN @moving_average_size::integer PRECEDING AND CURRENT ROW)
113
+ OVER(
114
+ PARTITION BY t .id
115
+ ORDER BY pj .completed_at
116
+ ROWS BETWEEN @moving_average_size::integer PRECEDING AND CURRENT ROW)
114
117
AS avg_build_time_sec,
115
118
COUNT (* ) OVER(PARTITION BY t .id ) as job_count
116
119
FROM
@@ -121,33 +124,33 @@ FROM
121
124
templates) AS t
122
125
LEFT JOIN
123
126
(SELECT
124
- workspace_id,
125
- template_version_id,
126
- job_id
127
+ workspace_id,
128
+ template_version_id,
129
+ job_id
127
130
FROM
128
- workspace_builds)
131
+ workspace_builds)
129
132
AS
130
- wb
133
+ wb
131
134
ON
132
- t .id = wb .workspace_id AND t .active_version_id = wb .template_version_id
135
+ t .id = wb .workspace_id AND t .active_version_id = wb .template_version_id
133
136
LEFT JOIN
134
137
(SELECT
135
- id,
138
+ id,
136
139
completed_at,
137
140
EXTRACT(EPOCH FROM (completed_at - started_at)) AS exec_time_sec
138
141
FROM
139
- provisioner_jobs
142
+ provisioner_jobs
140
143
WHERE
141
- (completed_at IS NOT NULL ) AND (started_at IS NOT NULL ) AND
144
+ (completed_at IS NOT NULL ) AND (started_at IS NOT NULL ) AND
142
145
(completed_at >= @start_ts AND completed_at <= @end_ts) AND
143
- (canceled_at IS NULL ) AND
144
- ((error IS NULL ) OR (error = ' ' )))
146
+ (canceled_at IS NULL ) AND
147
+ ((error IS NULL ) OR (error = ' ' )))
145
148
AS
146
- pj
149
+ pj
147
150
ON
148
151
wb .job_id = pj .id )
149
152
SELECT
150
- id,
153
+ id,
151
154
avg_build_time_sec
152
155
FROM
153
156
query_with_all_job_count
You can’t perform that action at this time.
0 commit comments