Skip to content

Commit

Permalink
Merge pull request #8500 from evanchaoli/fix-check-gc
Browse files Browse the repository at this point in the history
Fix a bad SQL for check gc.
  • Loading branch information
xtremerui committed Aug 3, 2022
2 parents 043edf0 + a66d243 commit 0b54be4
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions atc/db/check_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@ 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)
)
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;
`)

if err1 != nil {
Expand Down

0 comments on commit 0b54be4

Please sign in to comment.