Add keyset pagination support for /users endpoint
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
- Query with offset pagination: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/21640/commands/70306
- Query with keyset pagination: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/21640/commands/70309
With keyset pagination ordered by:
How to set up and validate locally
-
In rails console enable feature flag
Feature.enable(:api_keyset_pagination_multi_order)
-
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"
-
Check the headers include offset pagination headers (eg. url includes
page
param, headers includeX-Next-Page
,X-Page, or
X-Total-Pages` -
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"
-
Check the headers include url in headers, url should include
cursor
. The headers should not includeX-Next-Page
,X-Page, or
X-Total-Pages` -
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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #419556 (closed)