Stop using a pool of threads for database operations

Now that squee cooperates with suspendable ports, this is unnecessary. Use a
connection pool to still support running queries in parallel using multiple
connections.
This commit is contained in:
Christopher Baines 2023-07-09 16:52:35 +01:00
parent 672ee6216e
commit 7251c7d653
15 changed files with 1292 additions and 1310 deletions

View file

@ -21,6 +21,7 @@
#:use-module (guix-data-service utils)
#:use-module (guix-data-service database)
#:use-module (guix-data-service web render)
#:use-module (guix-data-service web controller)
#:use-module (guix-data-service web query-parameters)
#:use-module (guix-data-service model build)
#:use-module (guix-data-service model system)
@ -41,7 +42,7 @@
(define parse-build-server
(lambda (v)
(letpar& ((build-servers
(with-thread-postgresql-connection
(with-resource-from-pool (connection-pool) conn
select-build-servers)))
(or (any (match-lambda
((id url lookup-all-derivations? lookup-builds?)
@ -88,39 +89,38 @@
(let ((system (assq-ref parsed-query-parameters 'system))
(target (assq-ref parsed-query-parameters 'target)))
(letpar& ((build-server-options
(with-thread-postgresql-connection
(lambda (conn)
(map (match-lambda
((id url lookup-all-derivations
lookup-builds)
(cons url id)))
(select-build-servers conn)))))
(with-resource-from-pool (connection-pool) conn
(map (match-lambda
((id url lookup-all-derivations
lookup-builds)
(cons url id)))
(select-build-servers conn))))
(build-stats
(with-thread-postgresql-connection
(lambda (conn)
(select-build-stats
conn
(assq-ref parsed-query-parameters
'build_server)
#:system system
#:target target))))
(with-resource-from-pool (connection-pool) conn
(select-build-stats
conn
(assq-ref parsed-query-parameters
'build_server)
#:system system
#:target target)))
(builds-with-context
(with-thread-postgresql-connection
(lambda (conn)
(select-builds-with-context
conn
(assq-ref parsed-query-parameters
'build_status)
(assq-ref parsed-query-parameters
'build_server)
#:system system
#:target target
#:limit (assq-ref parsed-query-parameters
'limit_results)))))
(with-resource-from-pool (connection-pool) conn
(select-builds-with-context
conn
(assq-ref parsed-query-parameters
'build_status)
(assq-ref parsed-query-parameters
'build_server)
#:system system
#:target target
#:limit (assq-ref parsed-query-parameters
'limit_results))))
(systems
(with-thread-postgresql-connection list-systems))
(call-with-resource-from-pool (connection-pool)
list-systems))
(targets
(with-thread-postgresql-connection valid-targets)))
(call-with-resource-from-pool (connection-pool)
valid-targets)))
(render-html
#:sxml (view-builds parsed-query-parameters