Draft: Cache objects being used in note policy checks in request
What does this MR do?
When we request for discussions, we also filter the notes we show if they're readable by user via policy checks.
When there are a number of notes (e.g. 100+) in discussions, it means that the policy check will run the same number of times.
The policies involved with it seems to instantiate the same objects for each note (e.g. noteable which can be an Issue, Merge Request or Epic, project).
This reduces those objects by caching it so the same object will be reused. The cache is scoped by request since it only needs to happen on the same request.
When tested locally, it reduced the response times of MergeRequests#discussions.json
endpoint to ~1s from 1.6s when cached.
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.)
Related to #335566 (closed)
Edited by Patrick Bajao