Extract shared approval context to reduce redundant computations
What does this MR do and why?
Contributes to #589598
Problem
When evaluating approval rules for a merge request, each
ApprovalWrappedRule independently computes overall_approver_ids
and committer filtering data. This causes N redundant computations
where N is the number of approval rules, leading to slow performance
on MRs with many rules.
Solution
Introduce Approvals::Context class to hold pre-computed shared data
across all approval rules. The context is created once in
ApprovalState and passed through to wrapped rules, providing:
-
overall_approver_ids: Set of user IDs who approved the MR -
committer_ids_for_filtering: Committer IDs for AR::Relation filter -
committers_for_filtering: Committer users for Array filtering
References
Screenshots or screen recordings
N/A - Performance optimization with no UI changes.
How to set up and validate locally
- Create an MR with multiple approval rules (especially CODEOWNERS rules)
- Query the
approvalSummaryGraphQL endpoint - Verify reduced CPU time compared to before this change
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Vasilii Iakliushin