diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-04-29 22:33:56 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-04-29 22:44:08 +0200 |
commit | b6a18f1093c88e82d2320d4d3f3c15c549b861be (patch) | |
tree | dbace257a26f4c70f109fef3a2569317ffecdcbb /app/models | |
parent | e28d1fa3cc2e8c2f696f6740c8a8441100542470 (diff) | |
download | gitlab-ce-b6a18f1093c88e82d2320d4d3f3c15c549b861be.tar.gz |
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.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project.rb | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index bbc929e9bd4..af62e8ecd90 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -735,19 +735,17 @@ class Project < ActiveRecord::Base end 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? - all_branches.reject! do |branch| - protected_branches_names.include?(branch.name) - end + repository.branches.reject do |branch| + protected_set.include?(branch.name) end - - all_branches end - def protected_branches_names - @protected_branches_names ||= protected_branches.map(&:name) + def protected_branch_names + @protected_branch_names ||= protected_branches.pluck(:name) end def root_ref?(branch) |