Fix unnecessary request in sync pagination #483
Merged
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.
Description
Makes use of the
next
field to end pagination early, instead of waiting for Spotify's API to return no data.Motivation and Context
Currently,
PageIterator
always sends one extra request to the API, because it does not checknext
to know if more data is available (unlike its async equivalent).Dependencies
None.
Type of change
Please delete options that are not relevant.
How has this been tested?
This has been tested by adding a
dbg!
call right before sending a request inPageIterator
's impl, then running thepagination_sync
example with and without this change.Tests were run using an account with 51 saved tracks, which should require two requests with
limit
set to 50.This is
pagination_sync
's output before the change:And this is its output after the change:
The output is the same, but the extraneous request has been eliminated.
Is this change properly documented?
N/A