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

View File

@ -8172,7 +8172,11 @@ const getWorkspaces = `-- name: GetWorkspaces :many
SELECT
workspaces.id, workspaces.created_at, workspaces.updated_at, workspaces.owner_id, workspaces.organization_id, workspaces.template_id, workspaces.deleted, workspaces.name, workspaces.autostart_schedule, workspaces.ttl, workspaces.last_used_at, COUNT(*) OVER () as count
FROM
workspaces
workspaces
JOIN
users
ON
workspaces.owner_id = users.id
LEFT JOIN LATERAL (
SELECT
workspace_builds.transition,
@ -8333,7 +8337,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 $11 :: integer > 0 THEN