-
Notifications
You must be signed in to change notification settings - Fork 902
refactor(coderd): collapse activityBumpWorkspace into a single query #9652
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
Changes from 1 commit
e25d8ab
1ee5403
a71a809
3e583d9
1829a25
cf5e55b
5bf3f51
9ac9424
0e8675c
a4a6355
0209449
d05d1f1
b75ff56
9272f4b
49dbc55
50f7578
dc37bf9
5dcb743
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self-review: I can inline this CTE if required, but I think the readability is important here. I'm preserving the comments from the original pure-Go implementation for reference. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
-- name: ActivityBumpWorkspace :exec | ||
WITH latest AS ( | ||
SELECT | ||
workspace_builds.id, | ||
workspace_builds.deadline, | ||
workspace_builds.max_deadline, | ||
workspaces.ttl, | ||
(workspace_builds.deadline + (workspaces.ttl/1000 || ' microsecond')::interval ) AS new_deadline | ||
FROM workspace_builds | ||
JOIN provisioner_jobs | ||
ON provisioner_jobs.id = workspace_builds.job_id | ||
JOIN workspaces | ||
ON workspaces.id = workspace_builds.workspace_id | ||
WHERE workspace_builds.workspace_id = $1::uuid | ||
AND workspace_builds.transition = 'start' | ||
AND workspace_builds.deadline > NOW() | ||
AND provisioner_jobs.completed_at IS NOT NULL | ||
ORDER BY workspace_builds.build_number ASC | ||
LIMIT 1 | ||
) | ||
UPDATE | ||
workspace_builds | ||
workspace_builds wb | ||
SET | ||
updated_at = $2, | ||
deadline = LEAST(workspace_builds.deadline + workspace.ttl, workspace_builds.max_deadline) | ||
updated_at = NOW(), | ||
deadline = CASE | ||
WHEN l.max_deadline = '0001-01-01 00:00:00' | ||
THEN l.new_deadline | ||
ELSE LEAST(l.new_deadline, l.max_deadline) | ||
END | ||
FROM latest l | ||
WHERE | ||
workspace_builds.id IN ( | ||
SELECT wb.id | ||
FROM workspace_builds wb | ||
JOIN provisioner_jobs pj | ||
ON pj.id = wb.job_id | ||
WHERE wb.workspace_id = $1 | ||
AND wb.transition == 'start' | ||
AND wb.deadline > $2 | ||
AND wb.deadline != wb.max_deadline | ||
AND pj.completed_at IS NOT NULL | ||
ORDER BY wb.build_number ASC | ||
LIMIT 1 | ||
); | ||
wb.id = l.id | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if this is used only by
ActivityBumpWorkspace
, then I would move it below/to the bottom.