Skip to content

Commit 5dcc74f

Browse files
committed
chore: remove excess join in GetQuotaConsumedForUser query
Filter is applied in original workspace query.
1 parent 17cc881 commit 5dcc74f

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

coderd/database/queries.sql.go

Lines changed: 3 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/quotas.sql

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ FROM
2828
INNER JOIN
2929
workspaces on wb.workspace_id = workspaces.id
3030
WHERE
31+
-- Only return workspaces that match the user + organization.
32+
-- Quotas are calculated per user per organization.
3133
workspaces.owner_id = @owner_id AND
3234
workspaces.organization_id = @organization_id
3335
ORDER BY
@@ -37,14 +39,5 @@ ORDER BY
3739
SELECT
3840
coalesce(SUM(daily_cost), 0)::BIGINT
3941
FROM
40-
workspaces
41-
INNER JOIN latest_builds ON
42-
latest_builds.workspace_id = workspaces.id
43-
WHERE
44-
NOT deleted AND
45-
-- We can likely remove these conditions since we check above.
46-
-- But it does not hurt to be defensive and make sure future query changes
47-
-- do not break anything.
48-
workspaces.owner_id = @owner_id AND
49-
workspaces.organization_id = @organization_id
42+
latest_builds
5043
;

0 commit comments

Comments
 (0)