Delete unreferenced derivations in batches

To avoid a long blocking query.
This commit is contained in:
Christopher Baines 2023-08-01 10:16:31 +01:00
parent 1c75394187
commit 7495085f63
1 changed files with 18 additions and 8 deletions

View File

@ -425,15 +425,25 @@ WHERE build_server_id = $1
build-server-ids)))
(define (delete-unreferenced-derivations-source-files conn)
(exec-query
conn
"
(define (delete-batch)
(exec-query
conn
"
DELETE FROM derivation_source_files
WHERE NOT EXISTS (
SELECT 1
FROM derivation_sources
WHERE derivation_source_file_id = derivation_source_files.id
)"))
WHERE id IN (
SELECT id
FROM derivation_source_files
WHERE NOT EXISTS (
SELECT 1
FROM derivation_sources
WHERE derivation_source_file_id = derivation_source_files.id
)
LIMIT 100
)
RETURNING id"))
(while (not (null? (delete-batch)))
#t))
(define (maybe-delete-derivation conn id)
(match (map