diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-04-03 19:10:58 +0300 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-04-03 19:19:53 +0300 |
commit | b8c7bef5c092152ea85d1840e587cfc04293e1d7 (patch) | |
tree | 51338a1599fa24d4e42c4eb7b6c02ac91555a73c /app/controllers/projects/settings | |
parent | 65f3d5062f081d8f8ebf727a3408650d90ec9711 (diff) |
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/controllers/projects/settings')
-rw-r--r-- | app/controllers/projects/settings/repository_controller.rb | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb index 5160ee5e1e4..a87927fe1ec 100644 --- a/app/controllers/projects/settings/repository_controller.rb +++ b/app/controllers/projects/settings/repository_controller.rb @@ -4,8 +4,7 @@ module Projects before_action :authorize_admin_project! def show - @deploy_keys = DeployKeysPresenter - .new(@project, current_user: current_user) + @deploy_keys = DeployKeysPresenter.new(@project, current_user: current_user) define_protected_refs end @@ -38,27 +37,17 @@ module Projects } end - #TODO: Move to Protections::TagMatcher.new(project).unprotected - def unprotected_tags - exact_protected_tag_names = @project.protected_tags.reject(&:wildcard?).map(&:name) - tag_names = @project.repository.tags.map(&:name) - non_open_tag_names = Set.new(exact_protected_tag_names).intersection(Set.new(tag_names)) - @project.repository.tags.reject { |tag| non_open_tag_names.include? tag.name } + def protectable_tags_for_dropdown + { open_tags: ProtectableDropdown.new(@project, :tags).hash } end - def unprotected_tags_hash - tags = unprotected_tags.map { |tag| { text: tag.name, id: tag.name, title: tag.name } } - { open_tags: tags } - end - - def open_branches - branches = @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } - { open_branches: branches } + def protectable_branches_for_dropdown + { open_branches: ProtectableDropdown.new(@project, :branches).hash } end def load_gon_index - gon.push(open_branches) - gon.push(unprotected_tags_hash) + gon.push(protectable_tags_for_dropdown) + gon.push(protectable_branches_for_dropdown) gon.push(access_levels_options) end end |