aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--guix-data-service/model/git-branch.scm21
-rw-r--r--guix-data-service/web/controller.scm38
2 files changed, 59 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
diff --git a/guix-data-service/web/controller.scm b/guix-data-service/web/controller.scm
index bc489b5..76b6a59 100644
--- a/guix-data-service/web/controller.scm
+++ b/guix-data-service/web/controller.scm
@@ -682,6 +682,44 @@
'after_date)
#:before-date (assq-ref parsed-query-parameters
'before_date)))))))
+ ((GET "branch" branch-name "latest-processed-revision")
+ (let ((commit-hash
+ (latest-processed-commit-for-branch conn branch-name)))
+ (if commit-hash
+ (render-view-revision mime-types
+ conn
+ commit-hash)
+ (render-unknown-revision mime-types
+ conn
+ commit-hash))))
+ ((GET "branch" branch-name "latest-processed-revision" "packages")
+ (let ((commit-hash
+ (latest-processed-commit-for-branch conn branch-name)))
+ (if commit-hash
+ (let ((parsed-query-parameters
+ (guard-against-mutually-exclusive-query-parameters
+ (parse-query-parameters
+ request
+ `((after_name ,identity)
+ (field ,identity #:multi-value
+ #:default ("version" "synopsis"))
+ (search_query ,identity)
+ (limit_results ,parse-result-limit
+ #:no-default-when (all_results)
+ #:default 100)
+ (all_results ,parse-checkbox-value)))
+ ;; You can't specify a search query, but then also limit the
+ ;; results by filtering for after a particular package name
+ '((after_name search_query)
+ (limit_results all_results)))))
+
+ (render-revision-packages mime-types
+ conn
+ commit-hash
+ parsed-query-parameters))
+ (render-unknown-revision mime-types
+ conn
+ commit-hash))))
((GET "gnu" "store" filename)
;; These routes are a little special, as the extensions aren't used for
;; content negotiation, so just use the path from the request