Add preload for custom roles
What does this MR do and why?
- Separate MR included custom roles in
ProjectPolicy
logic: !98694 (merged) - But that was also raising N+1 errors all over the place.
- This MR adds a preloader that we will take advantage of in the above MR to prevent N+1 errors.
- In a single query, the preloader searches for all custom roles that enable :download_code for a collection of projects.
- When we start using the preloader, we will save the results of the
preloader query on a virtual attribute on the user called
preloaded_custom_roles
- To find a custom role that enables download code for a single project,
we will use the
User#download_code_for?
method - This approach suggested here: !98694 (comment 1126102161)
Database
Preloader query: https://explain.depesz.com/s/shQU
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Adam Hegyi