aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2024-05-12 23:30:57 +0100
committerChristopher Baines <mail@cbaines.net>2024-05-12 23:30:57 +0100
commit22f43a1e8c1d59a6038e62d33e926dfd3611d12d (patch)
tree9468152b5a97e86299b22367c7a875b447c6f010
parent6c3dc4e334cf7adad09ab2f49247143eadc2095b (diff)
downloadqa-frontpage-22f43a1e8c1d59a6038e62d33e926dfd3611d12d.tar
qa-frontpage-22f43a1e8c1d59a6038e62d33e926dfd3611d12d.tar.gz
Do less in the with-sqlite-cache transaction
-rw-r--r--guix-qa-frontpage/database.scm62
1 files changed, 32 insertions, 30 deletions
diff --git a/guix-qa-frontpage/database.scm b/guix-qa-frontpage/database.scm
index 5649c36..51c0255 100644
--- a/guix-qa-frontpage/database.scm
+++ b/guix-qa-frontpage/database.scm
@@ -465,39 +465,41 @@ SELECT data, timestamp FROM cache WHERE key = :key"
(when (if (procedure? store-computed-value?)
(apply store-computed-value? vals)
store-computed-value?)
- (database-call-with-transaction
- database
- (lambda (db)
- (let ((cleanup-statement
- (sqlite-prepare
- db
- "
+ (let ((vals-string
+ (call-with-output-string
+ (lambda (port)
+ (write vals port)))))
+ (database-call-with-transaction
+ database
+ (lambda (db)
+ (let ((cleanup-statement
+ (sqlite-prepare
+ db
+ "
DELETE FROM cache WHERE key = :key"
- #:cache? #t))
- (insert-statement
- (sqlite-prepare
- db
- "
+ #:cache? #t))
+ (insert-statement
+ (sqlite-prepare
+ db
+ "
INSERT INTO cache (key, timestamp, data)
VALUES (:key, :timestamp, :data)"
- #:cache? #t)))
-
- (sqlite-bind-arguments
- cleanup-statement
- #:key string-key)
- (sqlite-step cleanup-statement)
- (sqlite-reset cleanup-statement)
-
- (sqlite-bind-arguments
- insert-statement
- #:key string-key
- #:timestamp (time-second (current-time))
- #:data (call-with-output-string
- (lambda (port)
- (write vals port))))
-
- (sqlite-step insert-statement)
- (sqlite-reset insert-statement)))))
+ #:cache? #t)))
+
+ (sqlite-bind-arguments
+ cleanup-statement
+ #:key string-key)
+ (sqlite-step cleanup-statement)
+ (sqlite-reset cleanup-statement)
+
+ (sqlite-bind-arguments
+ insert-statement
+ #:key string-key
+ #:timestamp (time-second (current-time))
+ #:data vals-string)
+
+ (sqlite-step insert-statement)
+ (sqlite-reset insert-statement))))))
(apply values vals)))
(apply values cached-values))))