From 7881eec3152b19de1850c3ef54236f75ae5ed015 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 30 Dec 2019 11:26:23 +0000 Subject: [PATCH] Add a function to backfill missing derivation source file nars If the file exists in the local store, then read it and add an entry to the derivation_source_file_nars table. This will help to fill in the missing entries, as currently entries are only added when the derivation source file isn't in the database when the load new revision job runs. --- guix-data-service/model/derivation.scm | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/guix-data-service/model/derivation.scm b/guix-data-service/model/derivation.scm index 835a187..2122121 100644 --- a/guix-data-service/model/derivation.scm +++ b/guix-data-service/model/derivation.scm @@ -1045,6 +1045,33 @@ INSERT INTO derivation_source_file_nars ( (number->string uncompressed-size) (string-append "\\x" data-string)))))) +(define (backfill-derivation-source-file-nars conn) + (define (missing-batch) + (exec-query + conn + " +SELECT id, store_path +FROM derivation_source_files +WHERE id NOT IN ( + SELECT derivation_source_file_id FROM derivation_source_file_nars +) +LIMIT 1000")) + + (let loop ((batch (missing-batch))) + (unless (null? batch) + (for-each + (match-lambda + ((id source-file) + (if (file-exists? source-file) + (begin + (insert-derivation-source-file-nar conn + (string->number id) + source-file) + (simple-format #t "inserting ~A\n" source-file)) + (simple-format #t "missing ~A\n" source-file)))) + batch) + (loop (missing-batch))))) + (define (insert-missing-derivations conn derivation-ids-hash-table derivations)