Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] paging rel links #2883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/api/activitypub/users/repliesget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesNext() {
"id": targetStatus.URI + "/replies?limit=20&only_other_accounts=false",
"partOf": targetStatus.URI + "/replies?only_other_accounts=false",
"next": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies?limit=20&min_id=01FF25D5Q0DH7CHD57CTRS6WK0&only_other_accounts=false",
"prev": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies?limit=20&max_id=01FF25D5Q0DH7CHD57CTRS6WK0&only_other_accounts=false",
"prev": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies?limit=20&min_id=01FF25D5Q0DH7CHD57CTRS6WK0&only_other_accounts=false",
"orderedItems": []string{"http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0"},
"totalItems": 1,
})
Expand Down
50 changes: 30 additions & 20 deletions internal/paging/boundary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
tsmethurst marked this conversation as resolved.
Show resolved Hide resolved
+----------+ +----------+
|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 {
Expand Down
25 changes: 19 additions & 6 deletions internal/paging/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down