aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-08-01 10:16:31 +0100
committerChristopher Baines <mail@cbaines.net>2023-08-01 10:16:31 +0100
commit7495085f631a3589ecdf5f282b750a318b422394 (patch)
treebec724a54bcc8a96a86cd7c2c09d339c26501c15 /guix-data-service
parent1c7539418743e0dfe3a9cad22c414fd732daef8f (diff)
downloaddata-service-7495085f631a3589ecdf5f282b750a318b422394.tar
data-service-7495085f631a3589ecdf5f282b750a318b422394.tar.gz
Delete unreferenced derivations in batches
To avoid a long blocking query.
Diffstat (limited to 'guix-data-service')
-rw-r--r--guix-data-service/data-deletion.scm26
1 files changed, 18 insertions, 8 deletions
diff --git a/guix-data-service/data-deletion.scm b/guix-data-service/data-deletion.scm
index b48f78c..0dd4a78 100644
--- a/guix-data-service/data-deletion.scm
+++ b/guix-data-service/data-deletion.scm
@@ -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