Skip to content

Add keyset pagination for project/issues endpoint

Add Keyset Pagination to Project Issues API Endpoint

What does this MR do and why?

This MR adds keyset-based pagination support to the project issues API endpoint (GET /projects/:id/issues). Keyset pagination provides more efficient and stable pagination compared to offset-based pagination, especially for large datasets.

Key Changes

  • Adds keyset pagination support for the project issues endpoint
  • Supports ordering by: id, title, created_at, updated_at, due_date, relative_position, and weight
  • Excludes complex order options that require table joins: label_priority, popularity, milestone_due, and priority
  • Falls back to offset pagination for unsupported ordering options

Implementation Details

  1. Model Changes (app/models/issue.rb):

    • Added supported_keyset_orderings class method defining which fields support keyset pagination
  2. API Changes (lib/api/issues.rb):

    • Added cursor parameter support for keyset pagination
    • Uses paginate_with_strategies to handle both keyset and offset pagination
    • Automatically falls back to offset pagination for unsupported order options
  3. Documentation Updates (doc/api/issues.md, doc/api/rest/_index.md):

    • Added cursor parameter documentation
    • Updated REST API index to include project issues in the list of keyset-paginated endpoints

References

gitlab-com/gl-infra/production-engineering#26555 (closed)

Screenshots or screen recordings

Before After

How to set up and validate locally

  1. Make a request to the project issues endpoint with keyset pagination:

    curl -H "PRIVATE-TOKEN: your-token" \
     "http://localhost:3000/api/v4/projects/1/issues?pagination=keyset&per_page=2&order_by=created_at"
  2. Check the response headers for the Link header containing the cursor:

    Link: <http://localhost:3000/api/v4/projects/1/issues?pagination=keyset&per_page=2&order_by=created_at&cursor=eyJjcmVhdGVkX2F0IjoiMjAyNC0wMS0wMSIsImlkIjoxMjM0fQ%3D%3D>; rel="next"
  3. Use the cursor from the Link header in the next request:

    curl -H "PRIVATE-TOKEN: your-token" \
     "http://localhost:3000/api/v4/projects/1/issues?pagination=keyset&per_page=2&order_by=created_at&cursor=eyJjcmVhdGVkX2F0IjoiMjAyNC0wMS0wMSIsImlkIjoxMjM0fQ%3D%3D"
  4. Verify that:

    • Different pages of results are returned
    • The cursor changes between requests
    • No cursor is returned on the last page
    • Unsupported order options (like label_priority) fall back to offset pagination

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Gosia Ksionek

Merge request reports

Loading