aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2024-04-01 22:20:00 +0100
committerChristopher Baines <mail@cbaines.net>2024-04-01 22:20:00 +0100
commit9fcd615c1f62de72474a348a0bc935e87adfaa67 (patch)
tree736c705c78b66da2cf43022cb29daea7c2f2280c /guix-data-service
parentb5f59189e17161b2396adf7b5440f04a2a8d5c01 (diff)
downloaddata-service-9fcd615c1f62de72474a348a0bc935e87adfaa67.tar
data-service-9fcd615c1f62de72474a348a0bc935e87adfaa67.tar.gz
Remove the per-thread PostgreSQL connection code
As this has been replaced by a fibers resource pool.
Diffstat (limited to 'guix-data-service')
-rw-r--r--guix-data-service/database.scm72
1 files changed, 5 insertions, 67 deletions
diff --git a/guix-data-service/database.scm b/guix-data-service/database.scm
index 7270e90..0b5175a 100644
--- a/guix-data-service/database.scm
+++ b/guix-data-service/database.scm
@@ -29,10 +29,7 @@
with-postgresql-connection
open-postgresql-connection
-
- with-postgresql-connection-per-thread
- with-thread-postgresql-connection
- close-thread-postgresql-connection
+ close-postgresql-connection
with-postgresql-transaction
@@ -116,6 +113,10 @@
conn))
+(define (close-postgresql-connection conn name)
+ (pg-conn-finish conn)
+ (decrement-connection-gauge name))
+
(define (run-sqitch)
(with-postgresql-connection
"sqitch"
@@ -201,69 +202,6 @@
(define %postgresql-connections-name
(make-parameter #f))
-(define* (with-postgresql-connection-per-thread name thunk
- #:key (statement-timeout #f))
- (parameterize ((%postgresql-connection-parameters
- (list name statement-timeout))
- (%postgresql-connections-hash-table
- (make-hash-table))
- (%postgresql-connections-name
- name))
- (call-with-values
- thunk
- (lambda vals
- (hash-for-each
- (lambda (thread conn)
- (pg-conn-finish conn)
- (decrement-connection-gauge name))
- (%postgresql-connections-hash-table))
-
- (apply values vals)))))
-
-(define %thread-postgresql-connection
- (make-thread-local-fluid))
-
-(define (with-thread-postgresql-connection f)
- (define (set-current-thread-connection conn)
- (if conn
- (hash-set! (%postgresql-connections-hash-table)
- (current-thread)
- conn)
- (hash-remove! (%postgresql-connections-hash-table)
- (current-thread)))
- (fluid-set! %thread-postgresql-connection
- conn))
-
- (let ((conn (fluid-ref %thread-postgresql-connection)))
- (if conn
- ;; Assume an exception here could mean the connection has failed, so
- ;; close it
- (with-exception-handler
- (lambda (exn)
- (pg-conn-finish conn)
- (decrement-connection-gauge
- (%postgresql-connections-name))
- (set-current-thread-connection #f)
- (raise-exception exn))
- (lambda ()
- (f conn)))
-
- (let ((conn (apply open-postgresql-connection
- (%postgresql-connection-parameters))))
- (set-current-thread-connection conn)
-
- (f conn)))))
-
-(define (close-thread-postgresql-connection)
- (let ((conn (fluid-ref %thread-postgresql-connection)))
- (when conn
- (pg-conn-finish conn)
- (hash-remove! (%postgresql-connections-hash-table)
- (current-thread))
- (fluid-set! %thread-postgresql-connection #f)
- (decrement-connection-gauge
- (%postgresql-connections-name)))))
-
(define* (with-postgresql-transaction conn f
#:key always-rollback?)
(exec-query conn "BEGIN;")