Commit b6a18f10 authored by Yorick Peterse's avatar Yorick Peterse

Tweak checking branches in Project#open_branches

This changes 4 things:

1. Project#protected_branches_names has been renamed to
   Project#protected_branch_names.

2. Project#open_branches uses a Set for the branch names as checking
   values in a Set is faster than checking values in a (large) Array.

3. Some redundant code in Project#open_branches has been removed.

4. Project#protected_branch_names now uses #pluck instead of #map,
   removing the need for loading entire DB records into memory.
parent e28d1fa3
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.8.0 (unreleased) v 8.8.0 (unreleased)
- Project#open_branches has been cleaned up and no longer loads entire records into memory.
- Make build status canceled if any of the jobs was canceled and none failed - Make build status canceled if any of the jobs was canceled and none failed
- Remove future dates from contribution calendar graph. - Remove future dates from contribution calendar graph.
- Use ActionDispatch Remote IP for Akismet checking - Use ActionDispatch Remote IP for Akismet checking
......
...@@ -735,19 +735,17 @@ class Project < ActiveRecord::Base ...@@ -735,19 +735,17 @@ class Project < ActiveRecord::Base
end end
def open_branches def open_branches
all_branches = repository.branches # We're using a Set here as checking values in a large Set is faster than
# checking values in a large Array.
protected_set = Set.new(protected_branch_names)
if protected_branches.present? repository.branches.reject do |branch|
all_branches.reject! do |branch| protected_set.include?(branch.name)
protected_branches_names.include?(branch.name)
end
end end
all_branches
end end
def protected_branches_names def protected_branch_names
@protected_branches_names ||= protected_branches.map(&:name) @protected_branch_names ||= protected_branches.pluck(:name)
end end
def root_ref?(branch) def root_ref?(branch)
......
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