Merge branch 'fix/remove-allow-n-plus-1-from-delete-merged-branches-service' into 'master'

Remove allow_n_plus_1 block from DeleteMergedBranchesService

Closes #37438 and gitaly#999

See merge request gitlab-org/gitlab-ce!17058
This commit is contained in:
Robert Speicher 2018-02-13 16:17:38 +00:00
commit 2007927956

View file

@ -6,18 +6,14 @@ class DeleteMergedBranchesService < BaseService
def execute
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :push_code, project)
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37438
Gitlab::GitalyClient.allow_n_plus_1_calls do
branches = project.repository.branch_names
branches = branches.select { |branch| project.repository.merged_to_root_ref?(branch) }
# Prevent deletion of branches relevant to open merge requests
branches -= merge_request_branch_names
# Prevent deletion of protected branches
branches = branches.reject { |branch| ProtectedBranch.protected?(project, branch) }
branches = project.repository.merged_branch_names
# Prevent deletion of branches relevant to open merge requests
branches -= merge_request_branch_names
# Prevent deletion of protected branches
branches = branches.reject { |branch| ProtectedBranch.protected?(project, branch) }
branches.each do |branch|
DeleteBranchService.new(project, current_user).execute(branch)
end
branches.each do |branch|
DeleteBranchService.new(project, current_user).execute(branch)
end
end