Add some basic pagination to the packages page
Lower powered devices will have problems displaying all ~9000+ packages, so return a smaller number by default.
This commit is contained in:
parent
8eac26b17d
commit
0bdc555ff8
|
@ -28,25 +28,46 @@
|
|||
"packages.version = vals.version AND "
|
||||
"packages.package_metadata_id = vals.package_metadata_id"))
|
||||
|
||||
(define (select-packages-in-revision conn commit-hash)
|
||||
(define* (select-packages-in-revision conn commit-hash
|
||||
#:key limit-results
|
||||
after-name)
|
||||
(define query
|
||||
"
|
||||
SELECT packages.name, packages.version, package_metadata.synopsis
|
||||
FROM packages
|
||||
INNER JOIN package_metadata
|
||||
ON packages.package_metadata_id = package_metadata.id
|
||||
WHERE packages.id IN (
|
||||
SELECT package_derivations.package_id
|
||||
FROM package_derivations
|
||||
INNER JOIN guix_revision_package_derivations
|
||||
ON package_derivations.id = guix_revision_package_derivations.package_derivation_id
|
||||
INNER JOIN guix_revisions
|
||||
ON guix_revision_package_derivations.revision_id = guix_revisions.id
|
||||
WHERE guix_revisions.commit = $1
|
||||
)
|
||||
ORDER BY packages.name, packages.version")
|
||||
(string-append "
|
||||
WITH data AS (
|
||||
SELECT packages.name, packages.version, package_metadata.synopsis
|
||||
FROM packages
|
||||
INNER JOIN package_metadata
|
||||
ON packages.package_metadata_id = package_metadata.id
|
||||
WHERE packages.id IN (
|
||||
SELECT package_derivations.package_id
|
||||
FROM package_derivations
|
||||
INNER JOIN guix_revision_package_derivations
|
||||
ON package_derivations.id = guix_revision_package_derivations.package_derivation_id
|
||||
INNER JOIN guix_revisions
|
||||
ON guix_revision_package_derivations.revision_id = guix_revisions.id
|
||||
WHERE guix_revisions.commit = $1
|
||||
)
|
||||
ORDER BY packages.name, packages.version
|
||||
), package_names AS (
|
||||
SELECT DISTINCT name
|
||||
FROM data"
|
||||
(if after-name
|
||||
"\nWHERE name > $2\n"
|
||||
"")
|
||||
" ORDER BY name"
|
||||
(if limit-results
|
||||
(string-append " LIMIT " (number->string limit-results))
|
||||
"")
|
||||
")
|
||||
SELECT data.*
|
||||
FROM data
|
||||
WHERE data.name IN (SELECT name FROM package_names);"))
|
||||
|
||||
(exec-query conn query (list commit-hash)))
|
||||
(exec-query conn query
|
||||
`(,commit-hash
|
||||
,@(if after-name
|
||||
(list after-name)
|
||||
'()))))
|
||||
|
||||
(define (count-packages-in-revision conn commit-hash)
|
||||
(define query
|
||||
|
|
|
@ -107,8 +107,15 @@
|
|||
|
||||
(define (render-revision-packages mime-types
|
||||
conn
|
||||
commit-hash)
|
||||
(let ((packages (select-packages-in-revision conn commit-hash)))
|
||||
commit-hash
|
||||
query-parameters)
|
||||
(let ((packages (select-packages-in-revision
|
||||
conn
|
||||
commit-hash
|
||||
#:limit-results (assq-ref query-parameters
|
||||
'limit_results)
|
||||
#:after-name (assq-ref query-parameters
|
||||
'after_name))))
|
||||
(case (most-appropriate-mime-type
|
||||
'(application/json text/html)
|
||||
mime-types)
|
||||
|
@ -123,7 +130,9 @@
|
|||
packages))))))
|
||||
(else
|
||||
(apply render-html
|
||||
(view-revision-packages commit-hash packages))))))
|
||||
(view-revision-packages commit-hash
|
||||
query-parameters
|
||||
packages))))))
|
||||
|
||||
(define (render-revision-package mime-types
|
||||
conn
|
||||
|
@ -441,10 +450,17 @@
|
|||
((GET "revision" commit-hash) (render-view-revision mime-types
|
||||
conn
|
||||
commit-hash))
|
||||
((GET "revision" commit-hash "packages") (render-revision-packages
|
||||
mime-types
|
||||
conn
|
||||
commit-hash))
|
||||
((GET "revision" commit-hash "packages")
|
||||
(let ((parsed-query-parameters
|
||||
(parse-query-parameters
|
||||
request
|
||||
`((after_name ,identity)
|
||||
(limit_results ,parse-result-limit #:default 100)))))
|
||||
|
||||
(render-revision-packages mime-types
|
||||
conn
|
||||
commit-hash
|
||||
parsed-query-parameters)))
|
||||
((GET "revision" commit-hash "package" name version) (render-revision-package
|
||||
mime-types
|
||||
conn
|
||||
|
|
|
@ -412,7 +412,9 @@
|
|||
(td (samp ,count))))))
|
||||
derivations-count)))))))))
|
||||
|
||||
(define (view-revision-packages revision-commit-hash packages)
|
||||
(define (view-revision-packages revision-commit-hash
|
||||
query-parameters
|
||||
packages)
|
||||
(layout
|
||||
#:extra-headers
|
||||
'((cache-control . ((max-age . 60))))
|
||||
|
@ -427,6 +429,28 @@
|
|||
(h3 (a (@ (href ,(string-append
|
||||
"/revision/" revision-commit-hash)))
|
||||
"Revision " (samp ,revision-commit-hash)))))
|
||||
(div
|
||||
(@ (class "row"))
|
||||
(div
|
||||
(@ (class "col-md-12"))
|
||||
(div
|
||||
(@ (class "well"))
|
||||
(form
|
||||
(@ (method "get")
|
||||
(action "")
|
||||
(class "form-horizontal"))
|
||||
,(form-horizontal-control
|
||||
"After name" query-parameters
|
||||
#:help-text
|
||||
"List packages that are alphabetically after the given name.")
|
||||
,(form-horizontal-control
|
||||
"Limit results" query-parameters
|
||||
#:help-text "The maximum number of packages by name to return.")
|
||||
(div (@ (class "form-group form-group-lg"))
|
||||
(div (@ (class "col-sm-offset-2 col-sm-10"))
|
||||
(button (@ (type "submit")
|
||||
(class "btn btn-lg btn-primary"))
|
||||
"Update results")))))))
|
||||
(div
|
||||
(@ (class "row"))
|
||||
(div
|
||||
|
@ -453,7 +477,13 @@
|
|||
"/revision/" revision-commit-hash
|
||||
"/package/" name "/" version)))
|
||||
"More information")))))
|
||||
packages)))))))))
|
||||
packages)))))
|
||||
(div
|
||||
(@ (class "row"))
|
||||
(a (@ (href ,(string-append "/revision/" revision-commit-hash
|
||||
"/packages?after_name="
|
||||
(car (last packages)))))
|
||||
"Next page"))))))
|
||||
|
||||
(define (view-branches branches-with-most-recent-commits)
|
||||
(layout
|
||||
|
|
Loading…
Reference in New Issue