Remove the per-thread PostgreSQL connection code
As this has been replaced by a fibers resource pool.
This commit is contained in:
parent
b5f59189e1
commit
9fcd615c1f
1 changed files with 5 additions and 67 deletions
|
|
@ -29,10 +29,7 @@
|
||||||
|
|
||||||
with-postgresql-connection
|
with-postgresql-connection
|
||||||
open-postgresql-connection
|
open-postgresql-connection
|
||||||
|
close-postgresql-connection
|
||||||
with-postgresql-connection-per-thread
|
|
||||||
with-thread-postgresql-connection
|
|
||||||
close-thread-postgresql-connection
|
|
||||||
|
|
||||||
with-postgresql-transaction
|
with-postgresql-transaction
|
||||||
|
|
||||||
|
|
@ -116,6 +113,10 @@
|
||||||
|
|
||||||
conn))
|
conn))
|
||||||
|
|
||||||
|
(define (close-postgresql-connection conn name)
|
||||||
|
(pg-conn-finish conn)
|
||||||
|
(decrement-connection-gauge name))
|
||||||
|
|
||||||
(define (run-sqitch)
|
(define (run-sqitch)
|
||||||
(with-postgresql-connection
|
(with-postgresql-connection
|
||||||
"sqitch"
|
"sqitch"
|
||||||
|
|
@ -201,69 +202,6 @@
|
||||||
(define %postgresql-connections-name
|
(define %postgresql-connections-name
|
||||||
(make-parameter #f))
|
(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
|
(define* (with-postgresql-transaction conn f
|
||||||
#:key always-rollback?)
|
#:key always-rollback?)
|
||||||
(exec-query conn "BEGIN;")
|
(exec-query conn "BEGIN;")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue