Skip to content

Draft: Reduce scope of team members when policy checking in bulk

Tiger Watson requested to merge reduce-participant-query-scope into master

What does this MR do?

When applying policy rules to groups of multiple users at once (for example when determining the participants of an Issuable), all team members for the associated project are eagerly loaded to avoid querying for each member individually.

However, typically the number of participants is significantly lower than the total number of team members, which means we retrieve more users than necessary to compare the participants against.

To solve this, we can fetch only the team members that are already known participants. Users are still eagerly loaded, but only those that are relevant to the set of participants being checked against, making the initial query more performant.

#325337 (closed)

Query changes

before

SELECT
  "users".*
FROM
  "users"
  INNER JOIN "project_authorizations" ON "users"."id" = "project_authorizations"."user_id"
WHERE
  "project_authorizations"."project_id" = 278964

https://console.postgres.ai/shared/8b43f42a-24b4-42ac-bdb9-4deab98174f7

after

SELECT
  "users".*
FROM
  "users"
  INNER JOIN "project_authorizations" ON "users"."id" = "project_authorizations"."user_id"
WHERE
  "project_authorizations"."project_id" = 278964
  AND "project_authorizations"."user_id" IN (3167938, 1786152)

https://console.postgres.ai/shared/066e467a-c5af-47e2-bdf9-86e9eb9d7673

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Tiger Watson

Merge request reports