Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bad SQL for check gc. #8500

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions atc/db/check_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,12 @@ func (cl *checkLifecycle) DeleteCompletedChecks(logger lager.Logger) error {
}

_, err2 := cl.conn.Exec(`
WITH resource_builds AS (
SELECT distinct(last_check_build_id) as build_id
FROM resource_config_scopes
WHERE last_check_build_id IS NOT NULL
UNION ALL
SELECT distinct(in_memory_build_id) as build_id
FROM resources
WHERE in_memory_build_id IS NOT NULL
WITH expired_imb_ids AS (
SELECT distinct(build_id) AS build_id FROM check_build_events cbe
WHERE NOT EXISTS (SELECT 1 FROM resources WHERE in_memory_build_id = cbe.build_id) AND
NOT EXISTS (SELECT 1 FROM builds WHERE id = cbe.build_id)
evanchaoli marked this conversation as resolved.
Show resolved Hide resolved
)
DELETE FROM check_build_events WHERE build_id NOT IN (SELECT build_id FROM resource_builds)
DELETE FROM check_build_events cbe2 USING expired_imb_ids WHERE cbe2.build_id = expired_imb_ids.build_id;
evanchaoli marked this conversation as resolved.
Show resolved Hide resolved
`)

if err1 != nil {
Expand Down