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
3 changed files with 93 additions and 26 deletions
|
|
@ -28,25 +28,46 @@
|
||||||
"packages.version = vals.version AND "
|
"packages.version = vals.version AND "
|
||||||
"packages.package_metadata_id = vals.package_metadata_id"))
|
"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
|
(define query
|
||||||
"
|
(string-append "
|
||||||
SELECT packages.name, packages.version, package_metadata.synopsis
|
WITH data AS (
|
||||||
FROM packages
|
SELECT packages.name, packages.version, package_metadata.synopsis
|
||||||
INNER JOIN package_metadata
|
FROM packages
|
||||||
ON packages.package_metadata_id = package_metadata.id
|
INNER JOIN package_metadata
|
||||||
WHERE packages.id IN (
|
ON packages.package_metadata_id = package_metadata.id
|
||||||
SELECT package_derivations.package_id
|
WHERE packages.id IN (
|
||||||
FROM package_derivations
|
SELECT package_derivations.package_id
|
||||||
INNER JOIN guix_revision_package_derivations
|
FROM package_derivations
|
||||||
ON package_derivations.id = guix_revision_package_derivations.package_derivation_id
|
INNER JOIN guix_revision_package_derivations
|
||||||
INNER JOIN guix_revisions
|
ON package_derivations.id = guix_revision_package_derivations.package_derivation_id
|
||||||
ON guix_revision_package_derivations.revision_id = guix_revisions.id
|
INNER JOIN guix_revisions
|
||||||
WHERE guix_revisions.commit = $1
|
ON guix_revision_package_derivations.revision_id = guix_revisions.id
|
||||||
)
|
WHERE guix_revisions.commit = $1
|
||||||
ORDER BY packages.name, packages.version")
|
)
|
||||||
|
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 (count-packages-in-revision conn commit-hash)
|
||||||
(define query
|
(define query
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,15 @@
|
||||||
|
|
||||||
(define (render-revision-packages mime-types
|
(define (render-revision-packages mime-types
|
||||||
conn
|
conn
|
||||||
commit-hash)
|
commit-hash
|
||||||
(let ((packages (select-packages-in-revision conn 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
|
(case (most-appropriate-mime-type
|
||||||
'(application/json text/html)
|
'(application/json text/html)
|
||||||
mime-types)
|
mime-types)
|
||||||
|
|
@ -123,7 +130,9 @@
|
||||||
packages))))))
|
packages))))))
|
||||||
(else
|
(else
|
||||||
(apply render-html
|
(apply render-html
|
||||||
(view-revision-packages commit-hash packages))))))
|
(view-revision-packages commit-hash
|
||||||
|
query-parameters
|
||||||
|
packages))))))
|
||||||
|
|
||||||
(define (render-revision-package mime-types
|
(define (render-revision-package mime-types
|
||||||
conn
|
conn
|
||||||
|
|
@ -441,10 +450,17 @@
|
||||||
((GET "revision" commit-hash) (render-view-revision mime-types
|
((GET "revision" commit-hash) (render-view-revision mime-types
|
||||||
conn
|
conn
|
||||||
commit-hash))
|
commit-hash))
|
||||||
((GET "revision" commit-hash "packages") (render-revision-packages
|
((GET "revision" commit-hash "packages")
|
||||||
mime-types
|
(let ((parsed-query-parameters
|
||||||
conn
|
(parse-query-parameters
|
||||||
commit-hash))
|
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
|
((GET "revision" commit-hash "package" name version) (render-revision-package
|
||||||
mime-types
|
mime-types
|
||||||
conn
|
conn
|
||||||
|
|
|
||||||
|
|
@ -412,7 +412,9 @@
|
||||||
(td (samp ,count))))))
|
(td (samp ,count))))))
|
||||||
derivations-count)))))))))
|
derivations-count)))))))))
|
||||||
|
|
||||||
(define (view-revision-packages revision-commit-hash packages)
|
(define (view-revision-packages revision-commit-hash
|
||||||
|
query-parameters
|
||||||
|
packages)
|
||||||
(layout
|
(layout
|
||||||
#:extra-headers
|
#:extra-headers
|
||||||
'((cache-control . ((max-age . 60))))
|
'((cache-control . ((max-age . 60))))
|
||||||
|
|
@ -427,6 +429,28 @@
|
||||||
(h3 (a (@ (href ,(string-append
|
(h3 (a (@ (href ,(string-append
|
||||||
"/revision/" revision-commit-hash)))
|
"/revision/" revision-commit-hash)))
|
||||||
"Revision " (samp ,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
|
(div
|
||||||
(@ (class "row"))
|
(@ (class "row"))
|
||||||
(div
|
(div
|
||||||
|
|
@ -453,7 +477,13 @@
|
||||||
"/revision/" revision-commit-hash
|
"/revision/" revision-commit-hash
|
||||||
"/package/" name "/" version)))
|
"/package/" name "/" version)))
|
||||||
"More information")))))
|
"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)
|
(define (view-branches branches-with-most-recent-commits)
|
||||||
(layout
|
(layout
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue