Revert "Optimise inserting derivation inputs"
I'm concerned that this approach is more error prone and won't error if there
are issues with the data in the database.
This reverts commit 3081887b90.
This commit is contained in:
parent
5684add77e
commit
edeb89e0cf
1 changed files with 52 additions and 40 deletions
|
|
@ -1105,6 +1105,25 @@ ON CONFLICT DO NOTHING"
|
||||||
(vector->list (json-string->scm env_vars)))
|
(vector->list (json-string->scm env_vars)))
|
||||||
system))))
|
system))))
|
||||||
|
|
||||||
|
(define select-derivation-output-id
|
||||||
|
(mlambda (conn name path)
|
||||||
|
(match (exec-query
|
||||||
|
conn
|
||||||
|
"
|
||||||
|
SELECT derivation_outputs.id FROM derivation_outputs
|
||||||
|
INNER JOIN derivations
|
||||||
|
ON derivation_outputs.derivation_id = derivations.id
|
||||||
|
WHERE derivations.file_name = $1
|
||||||
|
AND derivation_outputs.name = $2"
|
||||||
|
(list path
|
||||||
|
name))
|
||||||
|
(((id))
|
||||||
|
id)
|
||||||
|
(()
|
||||||
|
(error (simple-format
|
||||||
|
#f "cannot find derivation-output with name ~A and path ~A"
|
||||||
|
name path))))))
|
||||||
|
|
||||||
(define (select-derivation-outputs-by-derivation-id conn id)
|
(define (select-derivation-outputs-by-derivation-id conn id)
|
||||||
(define query
|
(define query
|
||||||
(string-append
|
(string-append
|
||||||
|
|
@ -1377,49 +1396,42 @@ WHERE derivation_source_files.store_path = $1"
|
||||||
#f)))
|
#f)))
|
||||||
|
|
||||||
(define (insert-derivation-inputs conn derivation-ids derivations)
|
(define (insert-derivation-inputs conn derivation-ids derivations)
|
||||||
(let ((query-parts
|
(define (insert-into-derivation-inputs derivation-id output-ids)
|
||||||
(append-map!
|
(for-each
|
||||||
(lambda (derivation-id derivation)
|
(lambda (output-id)
|
||||||
(append-map!
|
|
||||||
(match-lambda
|
|
||||||
(($ <derivation-input> derivation-or-path sub-derivations)
|
|
||||||
(let ((path
|
|
||||||
(match derivation-or-path
|
|
||||||
((? derivation? d)
|
|
||||||
;; The first field changed to a derivation (from the file
|
|
||||||
;; name) in 5cf4b26d52bcea382d98fb4becce89be9ee37b55
|
|
||||||
(derivation-file-name d))
|
|
||||||
((? string? s)
|
|
||||||
s))))
|
|
||||||
(map (lambda (sub-derivation)
|
|
||||||
(string-append "("
|
|
||||||
(number->string derivation-id)
|
|
||||||
", '" path
|
|
||||||
"', '" sub-derivation "')"))
|
|
||||||
sub-derivations))))
|
|
||||||
(derivation-inputs derivation)))
|
|
||||||
(vector->list derivation-ids)
|
|
||||||
(vector->list derivations))))
|
|
||||||
|
|
||||||
(chunk-for-each!
|
|
||||||
(lambda (query-parts-chunk)
|
|
||||||
(exec-query
|
(exec-query
|
||||||
conn
|
conn
|
||||||
(string-append
|
"
|
||||||
"
|
|
||||||
INSERT INTO derivation_inputs (derivation_id, derivation_output_id)
|
INSERT INTO derivation_inputs (derivation_id, derivation_output_id)
|
||||||
SELECT vals.derivation_id, derivation_outputs.id
|
VALUES ($1, $2);"
|
||||||
FROM (VALUES "
|
(list (number->string derivation-id) output-id)))
|
||||||
(string-join query-parts-chunk ", ")
|
output-ids))
|
||||||
") AS vals (derivation_id, file_name, output_name)
|
|
||||||
INNER JOIN derivations
|
(vector-for-each
|
||||||
ON derivations.file_name = vals.file_name
|
(lambda (i derivation-id derivation)
|
||||||
INNER JOIN derivation_outputs
|
(let ((inputs (derivation-inputs derivation)))
|
||||||
ON derivation_outputs.derivation_id = derivations.id
|
(unless (null? inputs)
|
||||||
AND vals.output_name = derivation_outputs.name
|
(insert-into-derivation-inputs
|
||||||
ON CONFLICT DO NOTHING")))
|
derivation-id
|
||||||
1000
|
(append-map!
|
||||||
query-parts)))
|
(match-lambda
|
||||||
|
(($ <derivation-input> derivation-or-path sub-derivations)
|
||||||
|
(let ((path
|
||||||
|
(match derivation-or-path
|
||||||
|
((? derivation? d)
|
||||||
|
;; The first field changed to a derivation (from the file
|
||||||
|
;; name) in 5cf4b26d52bcea382d98fb4becce89be9ee37b55
|
||||||
|
(derivation-file-name d))
|
||||||
|
((? string? s)
|
||||||
|
s))))
|
||||||
|
(map (lambda (sub-derivation)
|
||||||
|
(select-derivation-output-id conn
|
||||||
|
sub-derivation
|
||||||
|
path))
|
||||||
|
sub-derivations))))
|
||||||
|
inputs)))))
|
||||||
|
derivation-ids
|
||||||
|
derivations))
|
||||||
|
|
||||||
(define (insert-derivation-sources conn derivation-id sources)
|
(define (insert-derivation-sources conn derivation-id sources)
|
||||||
(define (insert-into-derivation-sources derivation-source-file-ids)
|
(define (insert-into-derivation-sources derivation-source-file-ids)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue