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.
This commit is contained in:
parent
0bd1fc7e87
commit
13e2f87555
2 changed files with 59 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
(define-module (guix-data-service model git-branch)
|
(define-module (guix-data-service model git-branch)
|
||||||
|
#:use-module (ice-9 match)
|
||||||
#:use-module (squee)
|
#:use-module (squee)
|
||||||
#:use-module (srfi srfi-19)
|
#:use-module (srfi srfi-19)
|
||||||
#:use-module (guix-data-service model utils)
|
#:use-module (guix-data-service model utils)
|
||||||
|
|
@ -6,6 +7,7 @@
|
||||||
git-branches-for-commit
|
git-branches-for-commit
|
||||||
git-branches-with-repository-details-for-commit
|
git-branches-with-repository-details-for-commit
|
||||||
most-recent-commits-for-branch
|
most-recent-commits-for-branch
|
||||||
|
latest-processed-commit-for-branch
|
||||||
all-branches-with-most-recent-commit))
|
all-branches-with-most-recent-commit))
|
||||||
|
|
||||||
(define (insert-git-branch-entry conn
|
(define (insert-git-branch-entry conn
|
||||||
|
|
@ -75,6 +77,25 @@ WHERE git_branches.commit = $1")
|
||||||
query
|
query
|
||||||
(list branch-name)))
|
(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 (all-branches-with-most-recent-commit conn)
|
||||||
(define query
|
(define query
|
||||||
(string-append
|
(string-append
|
||||||
|
|
|
||||||
|
|
@ -682,6 +682,44 @@
|
||||||
'after_date)
|
'after_date)
|
||||||
#:before-date (assq-ref parsed-query-parameters
|
#:before-date (assq-ref parsed-query-parameters
|
||||||
'before_date)))))))
|
'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)
|
((GET "gnu" "store" filename)
|
||||||
;; These routes are a little special, as the extensions aren't used for
|
;; These routes are a little special, as the extensions aren't used for
|
||||||
;; content negotiation, so just use the path from the request
|
;; content negotiation, so just use the path from the request
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue