diff options
author | Rémy Coutable <remy@rymai.me> | 2017-11-06 13:29:17 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-11-06 13:31:23 +0100 |
commit | b20984dea2fbbb20bc2807903115076b2a1de461 (patch) | |
tree | c8fa65db75e4b84b85ab70a34769dd08e69f310e /lib/api/branches.rb | |
parent | d77b9715406f027a060f376199dbd1f56dd866b3 (diff) | |
download | gitlab-ce-b20984dea2fbbb20bc2807903115076b2a1de461.tar.gz |
Improve performance of the /projects/:id/repository/branches API endpoint
Mitigate a N+1 requests to Gitaly problem. Still one left.
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/api/branches.rb')
-rw-r--r-- | lib/api/branches.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 19152c9f395..cdef1b546a9 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -29,12 +29,11 @@ module API use :pagination end get ':id/repository/branches' do - branches = ::Kaminari.paginate_array(user_project.repository.branches.sort_by(&:name)) + repository = user_project.repository + branches = ::Kaminari.paginate_array(repository.branches.sort_by(&:name)) + merged_branch_names = repository.merged_branch_names(branches.map(&:name)) - # n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37442 - Gitlab::GitalyClient.allow_n_plus_1_calls do - present paginate(branches), with: Entities::Branch, project: user_project - end + present paginate(branches), with: Entities::Branch, project: user_project, merged_branch_names: merged_branch_names end resource ':id/repository/branches/:branch', requirements: BRANCH_ENDPOINT_REQUIREMENTS do |