aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/model
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-12-22 16:20:08 +0000
committerChristopher Baines <mail@cbaines.net>2019-12-22 16:20:08 +0000
commit69d95b133f2305dc0968687294eff398f3b62a15 (patch)
tree8f2d400875b516b23aa14dace1d866544d12aef4 /guix-data-service/model
parent639f24bb2260d979ed97df1bb4db589fd82b97a9 (diff)
downloaddata-service-69d95b133f2305dc0968687294eff398f3b62a15.tar
data-service-69d95b133f2305dc0968687294eff398f3b62a15.tar.gz
Extract out some functions from update-package-derivations-table
To allow these to be used independently.
Diffstat (limited to 'guix-data-service/model')
-rw-r--r--guix-data-service/model/package-derivation-by-guix-revision-range.scm77
1 files changed, 49 insertions, 28 deletions
diff --git a/guix-data-service/model/package-derivation-by-guix-revision-range.scm b/guix-data-service/model/package-derivation-by-guix-revision-range.scm
index 2e48389..70b1103 100644
--- a/guix-data-service/model/package-derivation-by-guix-revision-range.scm
+++ b/guix-data-service/model/package-derivation-by-guix-revision-range.scm
@@ -29,27 +29,13 @@
action time-taken)
result))
-(define (update-package-derivations-table conn
- git-repository-id
- guix-revision-id
- commit)
- ;; Lock the table to wait for other transactions to commit before updating
- ;; the table
+(define (delete-guix-revision-package-derivation-entries conn
+ git-repository-id
+ guix-revision-id
+ branch-name)
(exec-query
conn
"
-LOCK TABLE ONLY package_derivations_by_guix_revision_range
- IN SHARE ROW EXCLUSIVE MODE")
-
- (for-each
- (match-lambda
- ((branch-name)
- (log-time
- (simple-format #f "deleting package derivation entries for ~A" branch-name)
- (lambda ()
- (exec-query
- conn
- "
DELETE FROM package_derivations_by_guix_revision_range
WHERE git_repository_id = $1 AND
branch_name = $2 AND
@@ -60,15 +46,18 @@ WHERE git_repository_id = $1 AND
ON package_derivations.id = guix_revision_package_derivations.package_derivation_id
WHERE revision_id = $3
)"
- (list git-repository-id
- branch-name
- guix-revision-id))))
- (log-time
- (simple-format #f "inserting package derivation entries for ~A" branch-name)
- (lambda ()
- (exec-query
- conn
- "
+ (list git-repository-id
+ branch-name
+ guix-revision-id
+ branch-name)))
+
+(define (insert-guix-revision-package-derivation-entries conn
+ git-repository-id
+ guix-revision-id
+ branch-name)
+ (exec-query
+ conn
+ "
INSERT INTO package_derivations_by_guix_revision_range
SELECT DISTINCT
$1::integer AS git_repository_id,
@@ -109,7 +98,39 @@ WINDOW package_version AS (
RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
)
ORDER BY packages.name, packages.version"
- (list git-repository-id branch-name guix-revision-id))))))
+ (list git-repository-id
+ branch-name
+ guix-revision-id)))
+
+(define (update-package-derivations-table conn
+ git-repository-id
+ guix-revision-id
+ commit)
+ ;; Lock the table to wait for other transactions to commit before updating
+ ;; the table
+ (exec-query
+ conn
+ "
+LOCK TABLE ONLY package_derivations_by_guix_revision_range
+ IN SHARE ROW EXCLUSIVE MODE")
+
+ (for-each
+ (match-lambda
+ ((branch-name)
+ (log-time
+ (simple-format #f "deleting package derivation entries for ~A" branch-name)
+ (lambda ()
+ (delete-guix-revision-package-derivation-entries conn
+ git-repository-id
+ guix-revision-id
+ branch-name)))
+ (log-time
+ (simple-format #f "inserting package derivation entries for ~A" branch-name)
+ (lambda ()
+ (insert-guix-revision-package-derivation-entries conn
+ git-repository-id
+ guix-revision-id
+ branch-name)))))
(exec-query
conn
"SELECT name FROM git_branches WHERE commit = $1 AND git_repository_id = $2"