summaryrefslogtreecommitdiff
path: root/internal/paging
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-04-30 11:19:33 +0100
committerLibravatar GitHub <noreply@github.com>2024-04-30 12:19:33 +0200
commit4f87ef246cc15d2b4a3effb3dff5cf3ece9a44b3 (patch)
treee2c3bb90ce14db783120a37edf865c7e05c3634b /internal/paging
parent[chore]: Bump github.com/tdewolff/minify/v2 from 2.20.19 to 2.20.20 (#2875) (diff)
downloadgotosocial-4f87ef246cc15d2b4a3effb3dff5cf3ece9a44b3.tar.xz
[bugfix] paging rel links (#2883)
* fix paging so it uses correct cursor query parameter name * improved code comment * whoops, flip the cursoring :facepalm: * fix the broken test
Diffstat (limited to 'internal/paging')
-rw-r--r--internal/paging/boundary.go50
-rw-r--r--internal/paging/page.go25
2 files changed, 49 insertions, 26 deletions
diff --git a/internal/paging/boundary.go b/internal/paging/boundary.go
index 83d265515..bf4508aff 100644
--- a/internal/paging/boundary.go
+++ b/internal/paging/boundary.go
@@ -23,26 +23,36 @@ package paging
func EitherMinID(minID, sinceID string) Boundary {
/*
- Paging with `since_id` vs `min_id`:
-
- limit = 4 limit = 4
- +----------+ +----------+
- max_id--> |xxxxxxxxxx| | | <-- max_id
- +----------+ +----------+
- |xxxxxxxxxx| | |
- +----------+ +----------+
- |xxxxxxxxxx| | |
- +----------+ +----------+
- |xxxxxxxxxx| |xxxxxxxxxx|
- +----------+ +----------+
- | | |xxxxxxxxxx|
- +----------+ +----------+
- | | |xxxxxxxxxx|
- +----------+ +----------+
- since_id--> | | |xxxxxxxxxx| <-- min_id
- +----------+ +----------+
- | | | |
- +----------+ +----------+
+ Paging with `since_id` vs `min_id`:
+
+ limit = 4 limit = 4
+ +----------+ +----------+
+ max_id--> |xxxxxxxxxx| | | <-- max_id
+ +----------+ +----------+
+ |xxxxxxxxxx| | |
+ +----------+ +----------+
+ |xxxxxxxxxx| | |
+ +----------+ +----------+
+ |xxxxxxxxxx| |xxxxxxxxxx|
+ +----------+ +----------+
+ | | |xxxxxxxxxx|
+ +----------+ +----------+
+ | | |xxxxxxxxxx|
+ +----------+ +----------+
+ since_id--> | | |xxxxxxxxxx| <-- min_id
+ +----------+ +----------+
+ | | | |
+ +----------+ +----------+
+
+ To sum it up in words:
+
+ when paging with since_id, max_id is used as
+ the cursor value, and since_id provides a
+ limiting value to the results.
+
+ when paging with min_id, min_id is used as
+ the cursor value, and max_id provides a
+ limiting value to the results.
*/
switch {
diff --git a/internal/paging/page.go b/internal/paging/page.go
index a1cf76c74..8e8261396 100644
--- a/internal/paging/page.go
+++ b/internal/paging/page.go
@@ -289,14 +289,27 @@ func (p *Page) ToLinkURL(proto, host, path string, queryParams url.Values) *url.
queryParams = cloneQuery(queryParams)
}
- if p.Min.Value != "" {
- // A page-minimum query parameter is available.
- queryParams.Set(p.Min.Name, p.Min.Value)
+ var cursor string
+
+ // Depending on page ordering, the
+ // page will be cursored by either
+ // the min or max query parameter.
+ if p.order().Ascending() {
+ cursor = p.Min.Name
+ } else {
+ cursor = p.Max.Name
}
- if p.Max.Value != "" {
- // A page-maximum query parameter is available.
- queryParams.Set(p.Max.Name, p.Max.Value)
+ if cursor != "" {
+ if p.Min.Value != "" {
+ // Set page-minimum cursor value.
+ queryParams.Set(cursor, p.Min.Value)
+ }
+
+ if p.Max.Value != "" {
+ // Set page-maximum cursor value.
+ queryParams.Set(cursor, p.Max.Value)
+ }
}
if p.Limit > 0 {