Reapply "Optimise inserting derivation inputs"
Reverting this change entirely was too slow, so change the joins in the query
from inner joins to left joins, as this should mean that NULL values get
inserted if there are missing derivations or derivation outputs, which should
cause an error rather than silently skipping inserting the derivation inputs.
This reverts commit edeb89e0cf.
This commit is contained in:
parent
f456f73ba4
commit
de476a8b40
1 changed files with 38 additions and 48 deletions
|
|
@ -1141,25 +1141,6 @@ ON CONFLICT DO NOTHING"
|
||||||
(name missing-derivation-output-error-name)
|
(name missing-derivation-output-error-name)
|
||||||
(path missing-derivation-output-error-path))
|
(path missing-derivation-output-error-path))
|
||||||
|
|
||||||
(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)
|
|
||||||
(()
|
|
||||||
(raise-exception
|
|
||||||
(make-derivation-output-error 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
|
||||||
|
|
@ -1432,38 +1413,47 @@ 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)
|
||||||
(define (insert-into-derivation-inputs derivation-id output-ids)
|
(let ((query-parts
|
||||||
(for-each
|
(vector-fold
|
||||||
(lambda (output-id)
|
(lambda (_ result derivation-id derivation)
|
||||||
|
(fold
|
||||||
|
(lambda (drv-input result)
|
||||||
|
(match drv-input
|
||||||
|
(($ <derivation-input> (? derivation? d) sub-derivations)
|
||||||
|
(fold (lambda (sub-derivation result)
|
||||||
|
(cons
|
||||||
|
(string-append
|
||||||
|
"(" (number->string derivation-id)
|
||||||
|
", '" (derivation-file-name d)
|
||||||
|
"', '" sub-derivation "')")
|
||||||
|
result))
|
||||||
|
result
|
||||||
|
sub-derivations))))
|
||||||
|
result
|
||||||
|
(derivation-inputs derivation)))
|
||||||
|
'()
|
||||||
|
derivation-ids
|
||||||
|
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)
|
||||||
VALUES ($1, $2);"
|
SELECT vals.derivation_id, derivation_outputs.id
|
||||||
(list (number->string derivation-id) output-id)))
|
FROM (VALUES "
|
||||||
output-ids))
|
(string-join query-parts-chunk ", ")
|
||||||
|
") AS vals (derivation_id, file_name, output_name)
|
||||||
(vector-for-each
|
LEFT JOIN derivations
|
||||||
(lambda (i derivation-id derivation)
|
ON derivations.file_name = vals.file_name
|
||||||
(let ((inputs (derivation-inputs derivation)))
|
LEFT JOIN derivation_outputs
|
||||||
(unless (null? inputs)
|
ON derivation_outputs.derivation_id = derivations.id
|
||||||
(insert-into-derivation-inputs
|
AND derivation_outputs.name = vals.output_name
|
||||||
derivation-id
|
ON CONFLICT DO NOTHING")))
|
||||||
(append-map!
|
1000
|
||||||
(match-lambda
|
query-parts)))
|
||||||
;; The first field changed to a derivation (from the file name)
|
|
||||||
;; in 5cf4b26d52bcea382d98fb4becce89be9ee37b55, so guard against
|
|
||||||
;; that in the match
|
|
||||||
(($ <derivation-input> (? derivation? d) sub-derivations)
|
|
||||||
(let ((path (derivation-file-name d)))
|
|
||||||
(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