Skip to content

Add keyset pagination support for /users endpoint

Jarka Košanová requested to merge 419556-keyset-pagination-for-users into master

What does this MR do and why?

It introduces keyset pagination for /users endpoint. This should solve the performance problem we have with the endpoint (see SQL section below).

As I wanted to enable keyset pagination for multiple orderings, I changed the CursorBasedKeyset class to support this. In order to avoid potential problems, the changes are under a feature flag. (follow-up issue for rollout here).

SQL

With keyset pagination ordered by:

How to set up and validate locally

  1. In rails console enable feature flag

    Feature.enable(:api_keyset_pagination_multi_order)
  2. Visit the changed endpoint with offset pagination (old)

    curl -i --header "Authorization: Bearer TOKEN" "https://gdk.test:3443/api/v4/users?per_page=10&page=1"

  3. Check the headers include offset pagination headers (eg. url includes page param, headers include X-Next-Page, X-Page, or X-Total-Pages`

  4. Visit the changed endpoint with keyset pagination (new)

    curl -i --header "Authorization: Bearer TOKEN" "https://gdk.test:3443/api/v4/users?pagination=keyset&per_page=10&page=1"

  5. Check the headers include url in headers, url should include cursor. The headers should not include X-Next-Page, X-Page, or X-Total-Pages`

  6. Check with other orderings we support for the endpoint (id, name, username), eg.

    curl -i --header "Authorization: Bearer TOKEN" "https://gdk.test:3443/api/v4/users?pagination=keyset&order_by=username&sort=asc&per_page=10&page=1"

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #419556 (closed)

Edited by Jarka Košanová

Merge request reports