Move backfilling in to the server module and use the connection pool

To avoid using the old PostgreSQL connection per thread code.
This commit is contained in:
Christopher Baines 2024-04-01 21:51:29 +01:00
parent 5f5b8fc91d
commit b5f59189e1
3 changed files with 19 additions and 24 deletions

View file

@ -166,10 +166,8 @@ 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
@ -180,20 +178,17 @@ VALUES ($1, $2, $3, $4, $5)"
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
(lambda (conn)
(with-postgresql-transaction
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

View file

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

View file

@ -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