feat: order workspaces by running first (#7656)

* wip

* use updated sql

* wip

* Implement sorting in databasefake.go

* More fixes

* sql fmt

---------

Co-authored-by: Marcin Tojek <marcin@coder.com>
This commit is contained in:
Rodrigo Maia
2023-05-25 13:35:47 -03:00
committed by GitHub
parent 96a2e63809
commit d9299caa12
6 changed files with 134 additions and 126 deletions
+11 -2
View File
@@ -77,7 +77,11 @@ WHERE
SELECT
workspaces.*, COUNT(*) OVER () as count
FROM
workspaces
workspaces
JOIN
users
ON
workspaces.owner_id = users.id
LEFT JOIN LATERAL (
SELECT
workspace_builds.transition,
@@ -238,7 +242,12 @@ WHERE
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
-- @authorize_filter
ORDER BY
last_used_at DESC
(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) DESC,
LOWER(users.username) ASC,
LOWER(name) ASC
LIMIT
CASE
WHEN @limit_ :: integer > 0 THEN