-
Notifications
You must be signed in to change notification settings - Fork 894
feat: paginate workspaces page #4647
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 28 commits
770e473
13256ce
76071b9
bdb0614
86caa80
9317155
2a8c1b3
f501786
fbcfa36
939dcdc
1b142b4
ea9f240
09791c7
32168a5
4d8e565
5eea639
ef7f59d
eae13a2
b1ab93f
fdf74aa
7b6e822
644f305
8502b05
d838789
2efe49b
950ac50
296281d
e091841
78c231d
fc5df6c
bb2f0f3
6174b4f
3ab3505
a20827c
c06765b
6bd9683
de2ed63
ff8cb81
e609e5a
476019b
833c1af
1f62974
e182c19
8bd9afa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,135 @@ OFFSET | |
@offset_ | ||
; | ||
|
||
-- this duplicates the filtering in GetWorkspaces | ||
-- name: GetWorkspaceCount :one | ||
Comment on lines
+148
to
+149
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. I left an ad-hoc comment on the commit, but I think this is quite bug-prone. It's not extremely obvious that you have to change this when introducing a new filter type, which could lead to a mismatch with the workspaces and count. 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. Yeah, Colin thought this was the best thing for now but we have an issue to clean it up #4604 |
||
SELECT | ||
COUNT(*) as count | ||
FROM | ||
workspaces | ||
LEFT JOIN LATERAL ( | ||
SELECT | ||
workspace_builds.transition, | ||
provisioner_jobs.started_at, | ||
provisioner_jobs.updated_at, | ||
provisioner_jobs.canceled_at, | ||
provisioner_jobs.completed_at, | ||
provisioner_jobs.error | ||
FROM | ||
workspace_builds | ||
LEFT JOIN | ||
provisioner_jobs | ||
ON | ||
provisioner_jobs.id = workspace_builds.job_id | ||
WHERE | ||
workspace_builds.workspace_id = workspaces.id | ||
ORDER BY | ||
build_number DESC | ||
LIMIT | ||
1 | ||
) latest_build ON TRUE | ||
WHERE | ||
-- Optionally include deleted workspaces | ||
workspaces.deleted = @deleted | ||
AND CASE | ||
WHEN @status :: text != '' THEN | ||
CASE | ||
WHEN @status = 'pending' THEN | ||
latest_build.started_at IS NULL | ||
WHEN @status = 'starting' THEN | ||
latest_build.started_at IS NOT NULL AND | ||
latest_build.canceled_at IS NULL AND | ||
latest_build.completed_at IS NULL AND | ||
latest_build.updated_at - INTERVAL '30 seconds' < NOW() AND | ||
latest_build.transition = 'start'::workspace_transition | ||
|
||
WHEN @status = 'running' THEN | ||
latest_build.completed_at IS NOT NULL AND | ||
latest_build.canceled_at IS NULL AND | ||
latest_build.error IS NULL AND | ||
latest_build.transition = 'start'::workspace_transition | ||
|
||
WHEN @status = 'stopping' THEN | ||
latest_build.started_at IS NOT NULL AND | ||
latest_build.canceled_at IS NULL AND | ||
latest_build.completed_at IS NULL AND | ||
latest_build.updated_at - INTERVAL '30 seconds' < NOW() AND | ||
latest_build.transition = 'stop'::workspace_transition | ||
|
||
WHEN @status = 'stopped' THEN | ||
latest_build.completed_at IS NOT NULL AND | ||
latest_build.canceled_at IS NULL AND | ||
latest_build.error IS NULL AND | ||
latest_build.transition = 'stop'::workspace_transition | ||
|
||
WHEN @status = 'failed' THEN | ||
(latest_build.canceled_at IS NOT NULL AND | ||
latest_build.error IS NOT NULL) OR | ||
(latest_build.completed_at IS NOT NULL AND | ||
latest_build.error IS NOT NULL) | ||
|
||
WHEN @status = 'canceling' THEN | ||
latest_build.canceled_at IS NOT NULL AND | ||
latest_build.completed_at IS NULL | ||
|
||
WHEN @status = 'canceled' THEN | ||
latest_build.canceled_at IS NOT NULL AND | ||
latest_build.completed_at IS NOT NULL | ||
|
||
WHEN @status = 'deleted' THEN | ||
latest_build.started_at IS NOT NULL AND | ||
latest_build.canceled_at IS NULL AND | ||
latest_build.completed_at IS NOT NULL AND | ||
latest_build.updated_at - INTERVAL '30 seconds' < NOW() AND | ||
latest_build.transition = 'delete'::workspace_transition | ||
|
||
WHEN @status = 'deleting' THEN | ||
latest_build.completed_at IS NOT NULL AND | ||
latest_build.canceled_at IS NULL AND | ||
latest_build.error IS NULL AND | ||
latest_build.transition = 'delete'::workspace_transition | ||
|
||
ELSE | ||
true | ||
END | ||
ELSE true | ||
END | ||
-- Filter by owner_id | ||
AND CASE | ||
WHEN @owner_id :: uuid != '00000000-00000000-00000000-00000000' THEN | ||
owner_id = @owner_id | ||
ELSE true | ||
END | ||
-- Filter by owner_name | ||
AND CASE | ||
WHEN @owner_username :: text != '' THEN | ||
owner_id = (SELECT id FROM users WHERE lower(username) = lower(@owner_username) AND deleted = false) | ||
ELSE true | ||
END | ||
-- Filter by template_name | ||
-- There can be more than 1 template with the same name across organizations. | ||
-- Use the organization filter to restrict to 1 org if needed. | ||
AND CASE | ||
WHEN @template_name :: text != '' THEN | ||
template_id = ANY(SELECT id FROM templates WHERE lower(name) = lower(@template_name) AND deleted = false) | ||
ELSE true | ||
END | ||
-- Filter by template_ids | ||
AND CASE | ||
WHEN array_length(@template_ids :: uuid[], 1) > 0 THEN | ||
template_id = ANY(@template_ids) | ||
ELSE true | ||
END | ||
-- Filter by name, matching on substring | ||
AND CASE | ||
WHEN @name :: text != '' THEN | ||
name ILIKE '%' || @name || '%' | ||
ELSE true | ||
END | ||
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaceCount | ||
-- @authorize_filter | ||
; | ||
|
||
-- name: GetWorkspaceByOwnerIDAndName :one | ||
SELECT | ||
* | ||
|
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.
You could probably save some code by just converting this from
database.GetWorkspaceCountParams
todatabase.GetWorkspaceParams
and then callingq.GetAuthorizedWorkspace
but completely optional.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.
I agree with this!