diff options
author | Brett Walker <bwalker@gitlab.com> | 2017-10-12 15:31:43 +0200 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2017-10-12 15:31:43 +0200 |
commit | 528f9cde0588b0a6e70b1fa971a99eca439d0aa6 (patch) | |
tree | 9a9fb939858962ab7b49ca046606fc49acb27509 | |
parent | 6d3eea7b46d4b363b39a59e1fa17264de33d14d1 (diff) | |
download | gitlab-ce-528f9cde0588b0a6e70b1fa971a99eca439d0aa6.tar.gz |
moved throttling into the controller. if we hit the throttling
threshhold, a message is shown indicating we didn't perform the search
-rw-r--r-- | app/controllers/projects/commit_controller.rb | 7 | ||||
-rw-r--r-- | app/helpers/commits_helper.rb | 26 | ||||
-rw-r--r-- | app/models/repository.rb | 8 | ||||
-rw-r--r-- | app/views/projects/commit/branches.html.haml | 28 |
4 files changed, 43 insertions, 26 deletions
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 893763862ba..5b8a8159123 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -56,8 +56,11 @@ class Projects::CommitController < Projects::ApplicationController end def branches - @branches = @project.repository.branch_names_contains(commit.id, 1000) - @tags = @project.repository.tag_names_contains(commit.id, 1000) + # branch_names_contains/tag_names_contains can take a long time when there are thousands of + # branches/tags - each `git branch --contains xxx` request can consume a cpu core. + # so only do the query when there are a manageable number of branches/tags + @branches = @project.repository.branch_count > 1000 ? [:limit_exceeded] : @project.repository.branch_names_contains(commit.id) + @tags = @project.repository.tag_count > 1000 ? [:limit_exceeded] : @project.repository.tag_names_contains(commit.id) render layout: false end diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index ef22cafc2e2..8aaf3318f90 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -60,23 +60,33 @@ module CommitsHelper branches.include?(project.default_branch) ? branches.delete(project.default_branch) : branches.pop end + # returns a link formatted as a commit branch link + def commit_branch_link(url, text) + link_to(url, class: 'label label-gray ref-name') do + icon('code-fork') + " #{text}" + end + end + # Returns the sorted alphabetically links to branches, separated by a comma def commit_branches_links(project, branches) branches.sort.map do |branch| - link_to(project_ref_path(project, branch), class: "label label-gray ref-name") do - icon('code-fork') + " #{branch}" - end - end.join(" ").html_safe + commit_branch_link(project_ref_path(project, branch), branch) + end.join(' ').html_safe + end + + # returns a link formatted as a commit tag link + def commit_tag_link(url, text) + link_to(url, class: 'label label-gray ref-name') do + icon('tag') + " #{text}" + end end # Returns the sorted links to tags, separated by a comma def commit_tags_links(project, tags) sorted = VersionSorter.rsort(tags) sorted.map do |tag| - link_to(project_ref_path(project, tag), class: "label label-gray ref-name") do - icon('tag') + " #{tag}" - end - end.join(" ").html_safe + commit_tag_link(project_ref_path(project, tag), tag) + end.join(' ').html_safe end def link_to_browse_code(project, commit) diff --git a/app/models/repository.rb b/app/models/repository.rb index 3a083b76202..d725c65081d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -715,12 +715,12 @@ class Repository end end - def branch_names_contains(sha, limit = nil) - limit && branch_count > limit ? [] : refs_contains_sha('branch', sha) + def branch_names_contains(sha) + refs_contains_sha('branch', sha) end - def tag_names_contains(sha, limit = nil) - limit && tag_count > limit ? [] : refs_contains_sha('tag', sha) + def tag_names_contains(sha) + refs_contains_sha('tag', sha) end def local_branches diff --git a/app/views/projects/commit/branches.html.haml b/app/views/projects/commit/branches.html.haml index 911c9ddce06..398927fb50d 100644 --- a/app/views/projects/commit/branches.html.haml +++ b/app/views/projects/commit/branches.html.haml @@ -1,15 +1,19 @@ -- if @branches.any? || @tags.any? +- if @branches.any? - branch = commit_default_branch(@project, @branches) - = link_to(project_ref_path(@project, branch), class: "label label-gray ref-name") do - = icon('code-fork') - = branch + - if branch == :limit_exceeded + = commit_branch_link('#', _('Too many branches to search')) + - else + = commit_branch_link(project_ref_path(@project, branch), branch) - -# `commit_default_branch` deletes the default branch from `@branches`, - -# so only render this if we have more branches left - - if @branches.any? || @tags.any? - %span - = link_to "…", "#", class: "js-details-expand label label-gray" +-# `commit_default_branch` deletes the default branch from `@branches`, +-# so only render this if we have more branches or tags left +- if @branches.any? || @tags.any? + %span + = link_to "…", "#", class: "js-details-expand label label-gray" - %span.js-details-content.hide - = commit_branches_links(@project, @branches) if @branches.any? - = commit_tags_links(@project, @tags) if @tags.any? + %span.js-details-content.hide + = commit_branches_links(@project, @branches) if @branches.any? + - if @tags.first == :limit_exceeded + = commit_tag_link('#', _('Too many tags to search')) + - elsif @tags.any? + = commit_tags_links(@project, @tags) |