aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/datastore
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-04-24 15:56:16 +0100
committerChristopher Baines <mail@cbaines.net>2023-04-24 15:56:16 +0100
commit4e871b6d4c06110cfc43e6e73c07f872741b65df (patch)
treead7d416a83da5fcf63e3ccea855449de0708d66a /guix-build-coordinator/datastore
parent99902f43804483b3b457ddd7cd574d3bb2485f0f (diff)
downloadbuild-coordinator-4e871b6d4c06110cfc43e6e73c07f872741b65df.tar
build-coordinator-4e871b6d4c06110cfc43e6e73c07f872741b65df.tar.gz
Be rigerous about always using cached statements
The point here isn't really statement caching for performance, but using the cache of statements to keep track of them, and allowing them all to be finalized when the database connection is closed.
Diffstat (limited to 'guix-build-coordinator/datastore')
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm18
1 files changed, 7 insertions, 11 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 90fd3b6..97cd65b 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -253,11 +253,6 @@ CREATE TABLE IF NOT EXISTS mem.build_allocation_plan (
(sqlite-reset statement)
val))
-(define (sqlite-step-and-finalize statement)
- (let ((val (sqlite-step statement)))
- (sqlite-finalize statement)
- val))
-
(define* (db-optimize db db-filename metrics-registry
#:key (maybe-truncate-wal? #t))
(define (wal-size)
@@ -291,9 +286,10 @@ CREATE TABLE IF NOT EXISTS mem.build_allocation_plan (
(let* ((statement
(sqlite-prepare
db
- "PRAGMA wal_checkpoint(TRUNCATE);"))
+ "PRAGMA wal_checkpoint(TRUNCATE);"
+ #:cache? #t))
(result
- (match (sqlite-step-and-finalize statement)
+ (match (sqlite-step-and-reset statement)
(#(blocked? modified-page-count pages-moved-to-db)
(if (= blocked? 1)
(begin
@@ -778,13 +774,13 @@ SELECT id, name, description, active FROM agents ORDER BY id"
db
"
UPDATE agents SET active = :active WHERE id = :uuid"
- #:cache? #f)))
+ #:cache? #t)))
(sqlite-bind-arguments statement
#:uuid agent-uuid
#:active (if active? 1 0))
- (sqlite-step-and-finalize statement))))
+ (sqlite-step-and-reset statement))))
active?)
(define-method (datastore-find-agent-status
@@ -2508,7 +2504,7 @@ WHERE derivation_outputs.derivation_id = builds.derivation_id)"))
(string-append "LIMIT " (number->string limit) "\n")
"")))
(statement
- (sqlite-prepare db query #:cache? #f)))
+ (sqlite-prepare db query #:cache? #t)))
(when after-id
(sqlite-bind-arguments
@@ -2559,7 +2555,7 @@ WHERE derivation_outputs.derivation_id = builds.derivation_id)"))
uuid))))
#f)))))
statement)))
- (sqlite-finalize statement)
+ (sqlite-reset statement)
result)))))))