aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2024-04-01 21:51:29 +0100
committerChristopher Baines <mail@cbaines.net>2024-04-01 21:51:29 +0100
commitb5f59189e17161b2396adf7b5440f04a2a8d5c01 (patch)
tree6ce501e452f141fc3289cd3a4bf5a70c06bc7bda
parent5f5b8fc91dae1a8cd01c3cbee05242d0a46f123f (diff)
downloaddata-service-b5f59189e17161b2396adf7b5440f04a2a8d5c01.tar
data-service-b5f59189e17161b2396adf7b5440f04a2a8d5c01.tar.gz
Move backfilling in to the server module and use the connection pool
To avoid using the old PostgreSQL connection per thread code.
-rw-r--r--guix-data-service/model/guix-revision-package-derivation.scm29
-rw-r--r--guix-data-service/web/server.scm7
-rw-r--r--scripts/guix-data-service.in7
3 files changed, 19 insertions, 24 deletions
diff --git a/guix-data-service/model/guix-revision-package-derivation.scm b/guix-data-service/model/guix-revision-package-derivation.scm
index 2b0ed61..63c23e5 100644
--- a/guix-data-service/model/guix-revision-package-derivation.scm
+++ b/guix-data-service/model/guix-revision-package-derivation.scm
@@ -166,34 +166,29 @@ VALUES ($1, $2, $3, $4, $5)"
(loop (append level-counts (list count))))))))
system-ids-and-targets))
-(define (backfill-guix-revision-package-derivation-distribution-counts)
+(define (backfill-guix-revision-package-derivation-distribution-counts conn)
(define revision-ids
- (with-thread-postgresql-connection
- (lambda (conn)
- (map
- car
- (exec-query
- conn
- "
+ (map
+ car
+ (exec-query
+ conn
+ "
SELECT id
FROM guix_revisions
EXCEPT
SELECT guix_revision_id
FROM guix_revision_package_derivation_distribution_counts
-ORDER BY id DESC")))))
+ORDER BY id DESC")))
- (n-par-for-each
- 4
+ (for-each
(lambda (revision-id)
(simple-format #t "backfilling guix_revision_package_derivation_distribution_counts for revision ~A\n" revision-id)
- (with-thread-postgresql-connection
+ (with-postgresql-transaction
+ conn
(lambda (conn)
- (with-postgresql-transaction
+ (insert-guix-revision-package-derivation-distribution-counts
conn
- (lambda (conn)
- (insert-guix-revision-package-derivation-distribution-counts
- conn
- revision-id))))))
+ revision-id))))
revision-ids))
(define* (get-sql-to-select-package-and-related-derivations-for-revision
diff --git a/guix-data-service/web/server.scm b/guix-data-service/web/server.scm
index 1c0bce1..b73b186 100644
--- a/guix-data-service/web/server.scm
+++ b/guix-data-service/web/server.scm
@@ -35,6 +35,7 @@
#:use-module (guix-data-service database)
#:use-module (guix-data-service web controller)
#:use-module (guix-data-service web util)
+ #:use-module (guix-data-service model guix-revision-package-derivation)
#:export (%guix-data-service-metrics-registry
start-guix-data-service-web-server))
@@ -120,6 +121,12 @@
(resource-pool-default-timeout 5))
+ (spawn-fiber
+ (lambda ()
+ (with-resource-from-pool (connection-pool) conn
+ (backfill-guix-revision-package-derivation-distribution-counts
+ conn))))
+
(let ((render-metrics
(make-render-metrics registry)))
diff --git a/scripts/guix-data-service.in b/scripts/guix-data-service.in
index dc6b432..2393f1e 100644
--- a/scripts/guix-data-service.in
+++ b/scripts/guix-data-service.in
@@ -197,13 +197,6 @@
(lambda (port)
(simple-format port "~A\n" (getpid)))))
- (call-with-new-thread
- (lambda ()
- (with-postgresql-connection-per-thread
- "backfill"
- (lambda ()
- (backfill-guix-revision-package-derivation-distribution-counts)))))
-
(start-substitute-query-threads)
(call-with-new-thread