aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/model/derivation.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-12-29 16:03:04 +0000
committerChristopher Baines <mail@cbaines.net>2019-12-29 16:04:45 +0000
commit7e7cc1c8f17723bd909f84be11326cc1d47223d0 (patch)
treeccfd2ea0b0287e70f66c87d9851b5c291ca6830c /guix-data-service/model/derivation.scm
parentd15ba4f25c0dfcc6ea8e03982819e217d5bb35b9 (diff)
downloaddata-service-7e7cc1c8f17723bd909f84be11326cc1d47223d0.tar
data-service-7e7cc1c8f17723bd909f84be11326cc1d47223d0.tar.gz
Rework insert-derivation-sources to use a helper function
This means it returns ids properly.
Diffstat (limited to 'guix-data-service/model/derivation.scm')
-rw-r--r--guix-data-service/model/derivation.scm50
1 files changed, 6 insertions, 44 deletions
diff --git a/guix-data-service/model/derivation.scm b/guix-data-service/model/derivation.scm
index 692b3fe..835a187 100644
--- a/guix-data-service/model/derivation.scm
+++ b/guix-data-service/model/derivation.scm
@@ -974,18 +974,6 @@ WHERE derivation_source_files.store_path = $1"
");"))
(define (insert-derivation-sources conn derivation-id sources)
- (define (insert-into-derivation-source-files store-paths)
- (string-append
- "INSERT INTO derivation_source_files (store_path) VALUES "
- (string-join
- (map (lambda (store-path)
- (simple-format
- #f "('~A')" store-path))
- store-paths)
- ",")
- " RETURNING id"
- ";"))
-
(define (insert-into-derivation-sources derivation-source-file-ids)
(string-append
"INSERT INTO derivation_sources "
@@ -998,38 +986,12 @@ WHERE derivation_source_files.store_path = $1"
",")
";"))
- (let* ((existing-derivation-store-paths
- (exec-query->vhash
- conn
- (select-from-derivation-source-files sources)
- second ;; store_path
- first)) ;; id
-
- (missing-entries (filter
- (lambda (store-path)
- (not (vhash-assoc store-path
- existing-derivation-store-paths)))
- sources))
-
- (new-derivation-source-file-entries
- (if (null? missing-entries)
- '()
- (exec-query conn
- (insert-into-derivation-source-files missing-entries))))
-
- (new-entries-id-lookup-vhash
- (two-lists->vhash missing-entries
- new-derivation-source-file-entries))
-
- (sources-ids
- (map (lambda (store-path)
- (cdr
- (or (vhash-assoc store-path
- existing-derivation-store-paths)
- (vhash-assoc store-path
- new-entries-id-lookup-vhash)
- (error "missing derivation source files entry"))))
- sources)))
+ (let ((sources-ids
+ (insert-missing-data-and-return-all-ids
+ conn
+ "derivation_source_files"
+ '(store_path)
+ (map list sources))))
(exec-query conn
(insert-into-derivation-sources sources-ids))