Remove the per-thread PostgreSQL connection code

As this has been replaced by a fibers resource pool.
This commit is contained in:
Christopher Baines 2024-04-01 22:20:00 +01:00
parent b5f59189e1
commit 9fcd615c1f

View file

@ -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;")