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>
This commit is contained in:
parent
d77b971540
commit
b20984dea2
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Improve performance of the /projects/:id/repository/branches API endpoint
|
||||
merge_request: 15215
|
||||
author:
|
||||
type: performance
|
|
@ -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
|
||||
|
|
|
@ -244,7 +244,7 @@ module API
|
|||
expose :merged do |repo_branch, options|
|
||||
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37442
|
||||
Gitlab::GitalyClient.allow_n_plus_1_calls do
|
||||
options[:project].repository.merged_to_root_ref?(repo_branch.name)
|
||||
options[:project].repository.merged_to_root_ref?(repo_branch.name, options[:merged_branch_names])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -14,9 +14,11 @@ module API
|
|||
success ::API::Entities::Branch
|
||||
end
|
||||
get ":id/repository/branches" do
|
||||
branches = user_project.repository.branches.sort_by(&:name)
|
||||
repository = user_project.repository
|
||||
branches = repository.branches.sort_by(&:name)
|
||||
merged_branch_names = repository.merged_branch_names(branches.map(&:name))
|
||||
|
||||
present branches, with: ::API::Entities::Branch, project: user_project
|
||||
present branches, with: ::API::Entities::Branch, project: user_project, merged_branch_names: merged_branch_names
|
||||
end
|
||||
|
||||
desc 'Delete a branch'
|
||||
|
|
Loading…
Reference in New Issue