Skip to content

Let providers handle paging links to enable other paging methods #1981

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

Open
mikemahoney218-usgs opened this issue Mar 27, 2025 · 0 comments · May be fixed by #1982
Open

Let providers handle paging links to enable other paging methods #1981

mikemahoney218-usgs opened this issue Mar 27, 2025 · 0 comments · May be fixed by #1982
Labels
enhancement New feature or request

Comments

@mikemahoney218-usgs
Copy link
Contributor

Is your feature request related to a problem? Please describe.

We want to move away from limit-offset paging for the data we're serving from Postgres, as deep pages (requiring large offsets) are inefficient and can result in users downloading duplicate records and missing new records if data is appended to an earlier page. We're hoping to move to keyset paging instead, which means users will provide a (non-numeric) key with their queries to get the next page.

Unfortunately limit-offset paging is baked into the itemtypes API here:

if offset > 0:
prev = max(0, offset - limit)
content['links'].append(
{
'type': 'application/geo+json',
'rel': 'prev',
'title': l10n.translate('Items (prev)', request.locale),
'href': f'{uri}?offset={prev}{serialized_query_params}'
})
next_link = False
if content.get('numberMatched', -1) > (limit + offset):
next_link = True
elif len(content['features']) == limit:
next_link = True
if next_link:
next_ = offset + limit
next_href = f'{uri}?offset={next_}{serialized_query_params}'
content['links'].append(
{
'type': 'application/geo+json',
'rel': 'next',
'title': l10n.translate('Items (next)', request.locale),
'href': next_href
})

Describe the solution you'd like
Rather than assuming providers are using limit-offset paging, and therefore the last page was always at offset - limit and the next one at offset + limit, it'd be nice if providers could pass their own next links that would skip this entire chunk of code. I think a next link in the response should disable the generation of both prev and next links, as the Features standard mentions that prev links may be skipped based on implementation:

Providing prev links supports navigating back and forth between pages, but depending on the implementation approach it may be too complex to implement.

Describe alternatives you've considered
Potentially each provider should be responsible for implementing a sensible default pagination strategy, but that seems like a much higher lift than assuming (1) the provider is right if it provides a next link (2) the existing strategy can be used otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant