Skip to content

Projects::TreeController#show (json format) is calling Gitaly n+1 times per request

Projects::TreeController#show (json format) is calling Gitaly n+1 times per request

See https://gitlab.com/gitlab-org/gitlab-ce/blob/17251d0464e2c5a61c56f45b435fcf5356d4273b/app/controllers/projects/tree_controller.rb#L37-L38

:group/:project/tree/master?format=json

Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/38171

The problem is that last_commit_for_path is being called for each tree in to populate the trees[].last_commit structure. Does this even get consumed by the client?

Gitlab::GitalyClient::TooManyInvocationsError at /moocow/git/tree/master
========================================================================

> GitalyClient#migrate called 31 times from single request. Potential n+1?
The following call site called into Gitaly 22 times:
/Users/andrewn/code/gitlab/gitlab-development-kit/gitlab/lib/gitlab/gitaly_client.rb:131:in `migrate'
/Users/andrewn/code/gitlab/gitlab-development-kit/gitlab/lib/gitlab/git/repository.rb:1043:in `gitaly_migrate'
/Users/andrewn/code/gitlab/gitlab-development-kit/gitlab/app/models/repository.rb:633:in `last_commit_for_path'
/Users/andrewn/code/gitlab/gitlab-development-kit/gitlab/app/serializers/tree_entity.rb:7:in `block in <class:TreeEntity>'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/entity.rb:475:in `instance_exec'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/entity.rb:475:in `exec_with_object'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/block_exposure.rb:8:in `value'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/base.rb:79:in `valid_value'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/base.rb:63:in `serializable_value'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:61:in `block (2 levels) in serializable_value'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/base.rb:109:in `block in with_attr_path'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/options.rb:102:in `with_attr_path'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/base.rb:108:in `with_attr_path'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:60:in `block in serializable_value'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each_with_object'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:59:in `serializable_value'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/entity.rb:471:in `serializable_hash'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/base.rb:68:in `map'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/base.rb:68:in `serializable_value'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:61:in `block (2 levels) in serializable_value'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/base.rb:109:in `block in with_attr_path'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/options.rb:102:in `with_attr_path'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/base.rb:108:in `with_attr_path'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:60:in `block in serializable_value'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each_with_object'
/Users/andrewn/.gem/ruby/2.3.4/gems/grape-entity-0.6.0/lib/grape_entity/exposure/nesting_exposure.rb:59:in `serializable_value'