Skip to content

Optimize merge request permission check for references

Vasilii Iakliushin requested to merge 271242_memoize_merge_request_policy into master

What does this MR do?

Contributes to #271242 (closed)

Problem

ReferenceRedactorFilter verifies and hides references to merge requests that are not available for the user. It uses #can_read_reference? method and provides user and merge request objects to it.

But #can_read_reference? is an expensive call especially when we trigger it thousands of times.

Solution

:read_merge_request_iid depends on the user and the project. This allows us to cache the result of user-project pair permission check and apply it to all merge requests of the same project.

Screenshots (strongly suggested)

Before After
Screenshot_2021-05-12_at_15.27.48 Screenshot_2021-05-12_at_15.25.52
Screenshot_2021-05-12_at_15.27.55 is missing in flamegraph

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • 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 Vasilii Iakliushin

Merge request reports