Skip to content

Commit cfdd4a9

Browse files
authored
perf(coderd/database): add index on workspace_app_statuses.app_id (#21099)
1 parent d915910 commit cfdd4a9

File tree

6 files changed

+9
-3
lines changed

6 files changed

+9
-3
lines changed

coderd/aitasks_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,8 +1680,8 @@ func TestTasksNotification(t *testing.T) {
16801680
require.NoError(t, err)
16811681
require.Len(t, workspaceAgent.Apps, 1)
16821682
require.GreaterOrEqual(t, len(workspaceAgent.Apps[0].Statuses), 1)
1683-
latestStatusIndex := len(workspaceAgent.Apps[0].Statuses) - 1
1684-
require.Equal(t, tc.newAppStatus, workspaceAgent.Apps[0].Statuses[latestStatusIndex].State)
1683+
// Statuses are ordered by created_at DESC, so the first element is the latest.
1684+
require.Equal(t, tc.newAppStatus, workspaceAgent.Apps[0].Statuses[0].State)
16851685

16861686
if tc.isNotificationSent {
16871687
// Then: A notification is sent to the workspace owner (memberUser)

coderd/database/dump.sql

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP INDEX IF EXISTS workspace_app_statuses_app_id_idx;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE INDEX workspace_app_statuses_app_id_idx ON workspace_app_statuses (app_id, created_at DESC);

coderd/database/queries.sql.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceapps.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
7171
RETURNING *;
7272

7373
-- name: GetWorkspaceAppStatusesByAppIDs :many
74-
SELECT * FROM workspace_app_statuses WHERE app_id = ANY(@ids :: uuid [ ]);
74+
SELECT * FROM workspace_app_statuses WHERE app_id = ANY(@ids :: uuid [ ])
75+
ORDER BY created_at DESC, id DESC;
7576

7677
-- name: GetLatestWorkspaceAppStatusByAppID :one
7778
SELECT *

0 commit comments

Comments
 (0)