Create a new CredentialsInventoryResourceAccessTokensFinder

Related to #524159 (closed) & #511922 (closed)

Summary

During the testing of the rollout of #511922 (closed), we encountered performance issues due to the poor PAT query performance, high user count & an even higher tokens count (PATs & RATs).

Logs

Proposal

  • Make a new CredentialsInventoryResourceAccessTokensFinder or refactor CredentialsInventoryPersonalAccessTokensFinder to work with the resource_access_tokens API & UI for uniformity
  • The created CredentialsInventoryPersonalAccessTokensFinder fixed the PAT timeouts to unblock the Credentials Inventory API rollout but, the /groups/:id/manage/resource_access_tokens endpoint's performance is still inconsistent on large groups.

Why?

  • This solves the larger issue we have with our query performance
  • A more permanent solution might be to the following

Database

The Afflicted Query
SELECT
    personal_access_tokens.*
FROM
    personal_access_tokens
WHERE
    personal_access_tokens.user_id IN (
        SELECT
            users.id
        FROM
            users
            JOIN user_details AS user_detail ON user_detail.user_id = users.id
        WHERE
            users.user_type = 6 AND
            user_detail.bot_namespace_id IN (
                SELECT
                    namespaces.traversal_ids[array_length(
                        namespaces.traversal_ids,
                        1
                    )] AS id
                FROM
                    namespaces
                WHERE
                    traversal_ids @> '{4249178}'
            )
    ) AND
    personal_access_tokens.impersonation = false
ORDER BY
    personal_access_tokens.id ASC
LIMIT 20
OFFSET 0
Edited by Hakeem Abdul-Razak