-
Notifications
You must be signed in to change notification settings - Fork 552
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
Support backwards pagination with list's #auto_paging_each
#865
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, `#auto_paging_each` would always try to paginate forward, even if it was clear based on the list's current filters that the user had been intending to iterate backwards by specifying an `ending_before` filter exclusively. Here we implement backwards iteration by detecting this condition, reversing the current list data, and making new requests for the previous page (instead of the next one) as needed, which allows the user to handle elements in reverse logical order. Reversing the current page's list is intended as a minor user feature, but may possibly be contentious. For background, when backwards iterating in the API, results are still returned in "normal" order. So if I specifying `ending_before=7`, the next page would look like `[4, 5, 6`] instead of `[6, 5, 4]`. In `#auto_paging_each` I reverse it to `[6, 5, 4]` so it feels to the user like they're handling elements in the order they're iterating, which I think is okay. The reason it might be contentious though is that it could be a tad confusing to someone who already understands the normal `ending_before` ordering in the API. Fixes #864.
ob-stripe
approved these changes
Oct 10, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Very clean implementation and nice tests 👍
ruanltbg
reviewed
Oct 10, 2019
I can also confirm that now it is working properly. Thank you @brandur / @brandur-stripe. For fast implementation. |
ob-stripe
approved these changes
Oct 10, 2019
Thanks both! |
Released as 5.7.0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously,
#auto_paging_each
would always try to paginate forward,even if it was clear based on the list's current filters that the user
had been intending to iterate backwards by specifying an
ending_before
filter exclusively.
Here we implement backwards iteration by detecting this condition,
reversing the current list data, and making new requests for the
previous page (instead of the next one) as needed, which allows the user
to handle elements in reverse logical order.
Reversing the current page's list is intended as a minor user feature,
but may possibly be contentious. For background, when backwards
iterating in the API, results are still returned in "normal" order. So
if I specifying
ending_before=7
, the next page would look like[4, 5, 6
] instead of[6, 5, 4]
. In#auto_paging_each
I reverse it to[6, 5, 4]
so it feels to the user like they're handling elements in theorder they're iterating, which I think is okay. The reason it might be
contentious though is that it could be a tad confusing to someone who
already understands the normal
ending_before
ordering in the API.Fixes #864.
r? @ob-stripe
cc @ruanltbg Can you also take a look at this since it sounds like
you've got a good handle on how API list ordering works? Thanks!
cc @stripe/api-libraries