Skip to content

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.


See https://gitlab.com/gitlab-org/gitlab-ce/blob/05b25f5a5f0b6d1b694d27dea136a4c3341aba8d/app/models/project.rb#L2174-2181

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