Commit 50749135 authored by Ahmad Sherif's avatar Ahmad Sherif

Remove allow_n_plus_1 block from DeleteMergedBranchesService

Fixes #37438
Fixes gitaly#999
parent 80c1626b
...@@ -6,18 +6,14 @@ class DeleteMergedBranchesService < BaseService ...@@ -6,18 +6,14 @@ class DeleteMergedBranchesService < BaseService
def execute def execute
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :push_code, project) raise Gitlab::Access::AccessDeniedError unless can?(current_user, :push_code, project)
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37438 branches = project.repository.merged_branch_names
Gitlab::GitalyClient.allow_n_plus_1_calls do # Prevent deletion of branches relevant to open merge requests
branches = project.repository.branch_names branches -= merge_request_branch_names
branches = branches.select { |branch| project.repository.merged_to_root_ref?(branch) } # Prevent deletion of protected branches
# Prevent deletion of branches relevant to open merge requests branches = branches.reject { |branch| ProtectedBranch.protected?(project, branch) }
branches -= merge_request_branch_names
# Prevent deletion of protected branches
branches = branches.reject { |branch| ProtectedBranch.protected?(project, branch) }
branches.each do |branch| branches.each do |branch|
DeleteBranchService.new(project, current_user).execute(branch) DeleteBranchService.new(project, current_user).execute(branch)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment