Skip to content

Question: backwards paging #643

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

Closed
bart-degreed opened this issue Nov 28, 2019 · 5 comments
Closed

Question: backwards paging #643

bart-degreed opened this issue Nov 28, 2019 · 5 comments

Comments

@bart-degreed
Copy link
Contributor

Description

Recently IPageService.Backwards was introduced. As I'm implementing my own paging (via Elasticsearch), I wonder what this is intended for and how it can be used.

It would allow for a URL like /api/users?page[number]=-5, but what does that mean? My first thought was to interpret it as "5 pages back from the current position". But the absolute page offset is 1, unless specified explicitly in the url, which would defeat the purpose of having a relative offset.
...

Environment

latest master branch

@wisepotato
Copy link
Contributor

AFAIK this fails, and if it does, it would be "n-5"th page. @maurei ?

@maurei
Copy link
Member

maurei commented Nov 29, 2019

Backward paging is supported. Effectively it means pagination starts at the end of a result set and moves "backwards" from there, as opposed from moving forward at the beginning of a result set.

Example: Assume n resources with id 1 till n which by default are returned all at once ordered by id , i.e. schematically: { 1 }, { 2 } ... { n -1 }, { n }.

"Normal" forward paging would yield

  • for the first page the set { 1 } ... { 10 }, and
  • for the third page the set { 21 } ... { 30 }.

Backward paging would start at the end. It would field

  • for the first backward page (page[number]=-1) the set { n } ... { n-9 }, and
  • for the third backward page (-3) the set { n-20 } ... { n-29 }

Note: the page numbers are based-1, so there is no zero-th page.

"5 pages back from the current position"

Request scopes are stateless: there is no connection between different request scopes. As such there is no such thing as a "current position" relative to a preview request. The requested position is always specified by the client by including the page number (where omitting that parameter implies the first page)

Let me know if that answers your question

@maurei maurei closed this as completed Nov 29, 2019
@maurei
Copy link
Member

maurei commented Nov 29, 2019

@bart-degreed
Copy link
Contributor Author

Interesting. So it actually reverses the order of all individual items, instead of specifying an offset that is relative from the last page number. Thanks for the thorough explanation!

@bart-degreed
Copy link
Contributor Author

bart-degreed commented Nov 29, 2019

So this is identical to sorting in descending order, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants