Skip to content

Commit c062274

Browse files
dannykoppingevgeniy-scherbina
authored andcommitted
chore: exclude deleted templates from all queries
deleted templates cannot have associated workspaces, so it is logically invalid to include them Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent fa348d0 commit c062274

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

coderd/database/queries.sql.go

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

coderd/database/queries/prebuilds.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ WHERE w.id IN (
1515
AND b.template_version_id = t.active_version_id
1616
AND p.current_preset_id = @preset_id::uuid
1717
AND p.ready
18+
AND NOT t.deleted
1819
LIMIT 1 FOR UPDATE OF p SKIP LOCKED -- Ensure that a concurrent request will not select the same prebuild.
1920
)
2021
RETURNING w.id, w.name;
@@ -40,6 +41,7 @@ FROM templates t
4041
INNER JOIN template_version_presets tvp ON tvp.template_version_id = tv.id
4142
INNER JOIN organizations o ON o.id = t.organization_id
4243
WHERE tvp.desired_instances IS NOT NULL -- Consider only presets that have a prebuild configuration.
44+
AND NOT t.deleted
4345
AND (t.id = sqlc.narg('template_id')::uuid OR sqlc.narg('template_id') IS NULL);
4446

4547
-- name: GetRunningPrebuiltWorkspaces :many
@@ -70,6 +72,7 @@ FROM workspace_latest_builds wlb
7072
-- prebuilds that are still building.
7173
INNER JOIN templates t ON t.active_version_id = wlb.template_version_id
7274
WHERE wlb.job_status IN ('pending'::provisioner_job_status, 'running'::provisioner_job_status)
75+
AND NOT t.deleted
7376
GROUP BY t.id, wpb.template_version_id, wpb.transition, wlb.template_version_preset_id;
7477

7578
-- GetPresetsBackoff groups workspace builds by preset ID.
@@ -98,6 +101,7 @@ WITH filtered_builds AS (
98101
WHERE tvp.desired_instances IS NOT NULL -- Consider only presets that have a prebuild configuration.
99102
AND wlb.transition = 'start'::workspace_transition
100103
AND w.owner_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0'
104+
AND NOT t.deleted
101105
),
102106
time_sorted_builds AS (
103107
-- Group builds by preset, then sort each group by created_at.

0 commit comments

Comments
 (0)