Skip to content

Define pagination order for Paginator #8481

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

Merged
merged 3 commits into from
Jul 1, 2025
Merged

Conversation

andrewjstone
Copy link
Contributor

Pagination was previously hardcoded to be Ascending. I ran into an issue when paginating across multiple pages when descending order was required.

I fixed this by adding a parameter for the desired order into Paginator::new rather than hardcoding it. The rest is fixes to existing callsites.

Copy link
Collaborator

@davepacheco davepacheco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this.

@@ -506,7 +514,11 @@ impl<N> PaginatorHelper<N> {
PaginatorState::Middle { marker }
};

Paginator { batch_size: self.batch_size, state }
Paginator {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected that you'd need to change L512 (new code) to use first() instead of last() if the pagination order is descending. If you don't, then I'd expect instead of:

  • page 1: items 20-29
  • page 2: items 10-19
  • page 3: items 0-9

You'd get:

  • page 1: items 20-30
  • page 2: items 19-29
  • page 3: items 18-28

I might be wrong? It seems worth adding a test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review @davepacheco. it's definitely worth adding a test.

FWIW, on another branch I had done a quick test by adding a current_pagparams_desc that sorted in descending order and ran through inserted chicken list history that was more than a page long and it all seemed to work. However, this may be the case because of the order_by that I added on the datastore list side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a couple of tests in 0151f56 and everything seems to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, .last() working makes sense to me. Because we're ordering descending, I think this example:

  • page 1: items 20-29
  • page 2: items 10-19
  • page 3: items 0-9

would have the batches ordered in reverse. Page 1 would give you [29, 28, ..., 20], so .last() would give you 20, leading the next page to be [19, 18, ..., 10] and so on.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it -- that makes sense!

@@ -506,7 +514,11 @@ impl<N> PaginatorHelper<N> {
PaginatorState::Middle { marker }
};

Paginator { batch_size: self.batch_size, state }
Paginator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, .last() working makes sense to me. Because we're ordering descending, I think this example:

  • page 1: items 20-29
  • page 2: items 10-19
  • page 3: items 0-9

would have the batches ordered in reverse. Page 1 would give you [29, 28, ..., 20], so .last() would give you 20, leading the next page to be [19, 18, ..., 10] and so on.

@andrewjstone andrewjstone merged commit 3c473a8 into main Jul 1, 2025
16 checks passed
@andrewjstone andrewjstone deleted the ajs/pagination-helper-order branch July 1, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants