Follow-up from "Avoid Gitaly n+1 times per request for Project Branches performance"
!17998 (merged) eliminated N+1 queries whenever commit counts for each branch is cached, however if it's not cached, there's still N+1 queries.
We should restore allow_n_plus_1_calls
and add a test case which doesn't have cache enabled or make sure the cache is cold, so that we could probably detect that indeed there's no N+1 queries even if cache is cold.
The following discussion from !17998 (merged) should be addressed:
-
@godfat started a discussion: (+6 comments) @tnir Did you try to remove this cache? I tried to remove it and locally I see:
Gitlab::GitalyClient::TooManyInvocationsError in Projects::Branches#index Showing /home/godfat/gitlab-ce/app/views/projects/branches/_branch.html.haml where line #4 raised: GitalyClient#migrate called 36 times from single request. Potential n+1? The following call site called into Gitaly 12 times: /home/godfat/gitlab-ce/lib/gitlab/gitaly_client.rb:253:in `migrate' /home/godfat/gitlab-ce/lib/gitlab/git/repository.rb:1355:in `gitaly_migrate' /home/godfat/gitlab-ce/lib/gitlab/git/repository.rb:511:in `count_commits' /home/godfat/gitlab-ce/lib/gitlab/git/repository.rb:550:in `count_commits_between' /home/godfat/gitlab-ce/app/models/repository.rb:257:in `diverging_commit_counts'
I think the N+1 is coming from
raw_repository.count_commits_between
and I think the problem is still there, though since we have cache here it might not always happen.