Add offset-based pagination to list personal/group/project/impersonation tokens

The list of personal/group/project/impersonation tokens can be very large.

For example in production the user gitlab-qa (1614863) has 69366:

select count(id) FROM "personal_access_tokens" WHERE user_id = 1614863;
 count
-------
69366

(1 row)

According to this Sentry report the following query can take longer than 15000ms and cause a timeout:

SELECT "personal_access_tokens".* FROM "personal_access_tokens" WHERE "personal_access_tokens"."user_id" = 1614863 AND "personal_access_tokens"."impersonation" = FALSE AND (revoked = false AND (expires_at >= CURRENT_DATE OR expires_at IS NULL)) ORDER BY "personal_access_tokens"."expires_at" ASC;

Time: 1067.024 ms (00:01.067)

I suggest we change that above query for a offset-based query:

SELECT "personal_access_tokens".* FROM "personal_access_tokens" WHERE "personal_access_tokens"."user_id" = 1614863 AND "personal_access_tokens"."impersonation" = FALSE AND (revoked = false AND (expires_at >= CURRENT_DATE OR expires_at IS NULL)) ORDER BY "personal_access_tokens"."expires_at" ASC LIMIT 100 OFFSET 0;

Time: 766.373 ms

The frontend work to support pagination has been partially completed.

Related to this incident and this QA cleanup task.

Availability & Testing

Please trigger the full end-to-end test suite (run all manual e2e test jobs) to ensure they are fine.

Edited by Sanad Liaquat