aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/model/git-branch.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-06-13 23:14:04 +0100
committerChristopher Baines <mail@cbaines.net>2019-06-13 23:14:04 +0100
commit13e2f875551b0122270a1c2fa0dd0b4d8f4db60c (patch)
treebb84ba426c9c5982c41bd0c2379fcc79e6047aad /guix-data-service/model/git-branch.scm
parent0bd1fc7e87a3f6702f4c1fd97a23d3b13be94efc (diff)
downloaddata-service-13e2f875551b0122270a1c2fa0dd0b4d8f4db60c.tar
data-service-13e2f875551b0122270a1c2fa0dd0b4d8f4db60c.tar.gz
Support accessing the latest processed revision for a branch
This makes is easier to get the latest data for a branch in a single request, rather than making one request to find the latest revision, then another to get the data.
Diffstat (limited to 'guix-data-service/model/git-branch.scm')
-rw-r--r--guix-data-service/model/git-branch.scm21
1 files changed, 21 insertions, 0 deletions
diff --git a/guix-data-service/model/git-branch.scm b/guix-data-service/model/git-branch.scm
index 64f07c4..43774ed 100644
--- a/guix-data-service/model/git-branch.scm
+++ b/guix-data-service/model/git-branch.scm
@@ -1,4 +1,5 @@
(define-module (guix-data-service model git-branch)
+ #:use-module (ice-9 match)
#:use-module (squee)
#:use-module (srfi srfi-19)
#:use-module (guix-data-service model utils)
@@ -6,6 +7,7 @@
git-branches-for-commit
git-branches-with-repository-details-for-commit
most-recent-commits-for-branch
+ latest-processed-commit-for-branch
all-branches-with-most-recent-commit))
(define (insert-git-branch-entry conn
@@ -75,6 +77,25 @@ WHERE git_branches.commit = $1")
query
(list branch-name)))
+(define* (latest-processed-commit-for-branch conn branch-name)
+ (define query
+ (string-append
+ "SELECT git_branches.commit "
+ "FROM git_branches "
+ "INNER JOIN guix_revisions ON git_branches.commit = guix_revisions.commit "
+ "WHERE git_branches.name = $1 "
+ "ORDER BY datetime DESC "
+ "LIMIT 1"))
+
+ (match (exec-query
+ conn
+ query
+ (list branch-name))
+ (((commit-hash))
+ commit-hash)
+ ('()
+ #f)))
+
(define (all-branches-with-most-recent-commit conn)
(define query
(string-append