Gitaly N+1 in Project#fetch_branch_allows_collaboration?
We have a Gitaly "allow n+1" block on some code in Project#fetch_branch_allows_collaboration?
and we don't know why it's needed. All we know is that during tests, this method makes too many Gitaly calls.
This may be just a test issue. We have application caches that prevent some Gitaly calls, and the caches are usually cold during tests. Or maybe it's a real issue that affect users on large-enough repositories. At this point we don't know if this happens "in the wild", or whether it affects anyone.
Detected in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20639#note_88420078
I suspect it has something to do with this line:
merge_requests.any? { |merge_request| merge_request.can_be_merged_by?(user) }
It's also possible that this is one of those N+1's that disappears once the rails cache is warm.
Edited by Jacob Vosmaer