diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-04-03 17:10:58 +0100 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-04-03 17:19:53 +0100 |
commit | b8c7bef5c092152ea85d1840e587cfc04293e1d7 (patch) | |
tree | 51338a1599fa24d4e42c4eb7b6c02ac91555a73c /app/models/project.rb | |
parent | 65f3d5062f081d8f8ebf727a3408650d90ec9711 (diff) | |
download | gitlab-ce-b8c7bef5c092152ea85d1840e587cfc04293e1d7.tar.gz |
Extracted ProtectableDropdown to clean up Project#open_branches
Makes it clear this is only used in dropdowns, instead of cluttering up Project class. Since we only care about branch names, it is also possible to refactor out a lot of the set/reject logic.
A benchmark on Array/Set subtraction favoured using Arrays. This was with 5000 ‘branches’ and 2000 ‘protections’ to ensure a similar comparison to the commit which introduced using Set for intersection.
Comparison:
array subtraction: 485.8 i/s
set subtraction: 128.7 i/s - 3.78x slower
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 9 |
1 files changed, 0 insertions, 9 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 970de324a5b..4175bfab0a9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -865,15 +865,6 @@ class Project < ActiveRecord::Base @repo_exists = false end - # Branches that are not _exactly_ matched by a protected branch. - #TODO: Move to Protections::BranchMatcher.new(project).unprotecte - def open_branches - exact_protected_branch_names = protected_branches.reject(&:wildcard?).map(&:name) - branch_names = repository.branches.map(&:name) - non_open_branch_names = Set.new(exact_protected_branch_names).intersection(Set.new(branch_names)) - repository.branches.reject { |branch| non_open_branch_names.include? branch.name } - end - def root_ref?(branch) repository.root_ref == branch end |