diff options
author | Christopher Baines <mail@cbaines.net> | 2021-11-20 21:23:36 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2021-11-20 21:23:36 +0000 |
commit | 7756e6fdfd0a0ac737ecf233c9e62e52f7380fa3 (patch) | |
tree | c4771c944808da661293705c3aa3a2baf7ff6e59 | |
parent | 40869c6f4ca78a8e4757fb6f10e88353258569a1 (diff) | |
download | build-coordinator-7756e6fdfd0a0ac737ecf233c9e62e52f7380fa3.tar build-coordinator-7756e6fdfd0a0ac737ecf233c9e62e52f7380fa3.tar.gz |
Use prepared statements when inserting derivations
As I hope this might be a little faster, plus it's also neater.
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm index 9eaaa4a..828f9db 100644 --- a/guix-build-coordinator/datastore/sqlite.scm +++ b/guix-build-coordinator/datastore/sqlite.scm @@ -3323,13 +3323,14 @@ SELECT system FROM systems WHERE id = :id" (begin (unless (equal? (assq-ref derivation-details 'fixed-output?) fixed-output?) - (sqlite-exec - db - (simple-format #f - " -UPDATE derivations SET fixed_output = ~A WHERE name = '~A'" - (if fixed-output? 1 0) - derivation-name))) + (let ((statement (sqlite-prepare + db + " +UPDATE derivations SET fixed_output = :fixed_output WHERE name = :name" + #:cache? #t))) + (sqlite-bind-arguments statement + #:name derivation-name + #:fixed_output (if fixed-output? 1 0)))) 0) (let ((statement (sqlite-prepare @@ -3382,21 +3383,21 @@ INSERT OR IGNORE INTO derivations (name, system_id, fixed_output) (assoc-ref output-ids-by-name output-name)) (derivation-input-sub-derivations derivation-input)))) derivation-inputs))) - (sqlite-exec - db - (string-append - " -INSERT INTO derivation_inputs (derivation_id, derivation_output_id) VALUES " - (string-join - (map (lambda (derivation-output-id) - (simple-format - #f - "('~A', ~A)" - (db-find-derivation-id db derivation-name) - derivation-output-id)) - derivation-output-ids) - ", ") - ";"))))) + (let ((statement + (sqlite-prepare + db + " +INSERT INTO derivation_inputs (derivation_id, derivation_output_id) +VALUES (:derivation_id, :derivation_output_id)" + #:cache? #t))) + (for-each (lambda (derivation-output-id) + (sqlite-bind-arguments + statement + #:derivation_id (db-find-derivation-id db derivation-name) + #:derivation_output_id derivation-output-id) + (sqlite-step statement) + (sqlite-reset statement)) + derivation-output-ids))))) (define (db-insert-output db output) (let ((statement @@ -3485,24 +3486,25 @@ INSERT OR IGNORE INTO unbuilt_outputs (output_id) VALUES (:output_id)" (or (db-output->output-id db output) (db-insert-output db output)))))) - derivation-outputs))) - (sqlite-exec - db - (string-append - " -INSERT INTO derivation_outputs (derivation_id, name, output_id) VALUES " - (string-join - (map (match-lambda - ((name . output-id) - (simple-format - #f - "('~A', '~A', ~A)" - (db-find-derivation-id db derivation-name) - name - output-id))) - derivation-outputs-with-ids) - ", ") - ";")) + derivation-outputs)) + (statement + (sqlite-prepare + db + " +INSERT INTO derivation_outputs (derivation_id, name, output_id) + VALUES (:derivation_id, :name, :output_id)" + #:cache? #t))) + + (for-each (match-lambda + ((name . output-id) + (sqlite-bind-arguments + statement + #:derivation_id (db-find-derivation-id db derivation-name) + #:name name + #:output_id output-id) + (sqlite-step statement) + (sqlite-reset statement))) + derivation-outputs-with-ids) (for-each (lambda (output-id) (unless (output-has-successful-build? output-id) |