You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
handle the pagination Link headers for _list requests
The patchwork REST API defaults to sending a maximum of 30 items for API
requests which return a list. If the API request has more than 30 items,
then pwclient will only ever see the first page, and confuse users who
expect to see the entire set of items.
To handle this, the API includes 'Link' headers in the response which
indicate whether there is more data, and if so, what URL the data is
available at.
Add a method to extract the page number query parameter from the Link
header URL if it exists. Use this to recursively call _list() until there
is no more next page to obtain.
Implement extraction of the page number as a new static method which deals
with the complexity of analyzing the link headers. We only check for the
first link header, and only the first 'rel="next"' portion of it. Split
the discovered URL using urllib.parse.urlparse to find the query section
and locate the page=<value> bit.
This method avoids needing to add a new dependency (such as the requests
library), and should work for valid Link headers provided by patchwork. At
any point, if we fail to find the expected data, link parsing is stopped
and we return the set of items we've found so far.
This should fix pwclient to properly handle multiple pages of data. This
will likely cause some invocations of pwclient to slow down as they must
now query every available page. This is preferable to not returning the
available data.
A future improvement to reduce this would be to extend -n and -N to work
with pages so that we avoid downloading unnecessary data.
Signed-off-by: Jacob Keller <[email protected]>
0 commit comments