Draft: Reduce scope of team members when policy checking in bulk
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.
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
-
📋 Does this MR need a changelog?-
I have included a changelog entry. - [-] I have not included a changelog entry because _____.
-
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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