Network graph view performs N + 1 Gitaly calls

When lowering the allowed number of Gitaly calls, the following popped up on the NetworkGraph:

 Gitlab::GitalyClient::TooManyInvocationsError:
            GitalyClient#call called 31 times from single request. Potential n+1?
            The following call site called into Gitaly 24 times:
            lib/gitlab/gitaly_client.rb:161:in `call'
            lib/gitlab/gitaly_client/commit_service.rb:226:in `find_all_commits'
            lib/gitlab/git/commit.rb:132:in `block in find_all'
            lib/gitlab/git/wraps_gitaly_errors.rb:7:in `wrapped_gitaly_errors'
            lib/gitlab/git/commit.rb:131:in `find_all'
            app/models/network/graph.rb:118:in `find_commits'
            app/models/network/graph.rb:83:in `count_to_display_commit_in_center'
            app/models/network/graph.rb:43:in `collect_commits'
            app/models/network/graph.rb:18:in `initialize'
            app/controllers/projects/network_controller.rb:26:in `new'
            app/controllers/projects/network_controller.rb:26:in `block (2 levels) in show'
            app/controllers/projects/network_controller.rb:18:in `show'
            app/controllers/application_controller.rb:425:in `set_locale'
            lib/gitlab/query_limiting/middleware.rb:17:in `block in call'
            lib/gitlab/query_limiting/transaction.rb:39:in `run'
            lib/gitlab/query_limiting/middleware.rb:16:in `call'
            lib/gitlab/correlation_id.rb:15:in `use_id'
            lib/gitlab/testing/request_inspector_middleware.rb:33:in `call'
            lib/gitlab/testing/request_blocker_middleware.rb:47:in `call'

Now I'm not entirely sure why it calls find_all_commits at least 24 times yet although my first hunch was that a call is made for each branch in the repository.

Assignee Loading
Time tracking Loading