Commit 528f9cde authored by Brett Walker's avatar Brett Walker
Browse files

moved throttling into the controller. if we hit the throttling

threshhold, a message is shown indicating we didn't perform the search
parent 6d3eea7b
...@@ -56,8 +56,11 @@ def pipelines ...@@ -56,8 +56,11 @@ def pipelines
end end
def branches def branches
@branches = @project.repository.branch_names_contains(commit.id, 1000) # branch_names_contains/tag_names_contains can take a long time when there are thousands of
@tags = @project.repository.tag_names_contains(commit.id, 1000) # 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 render layout: false
end end
......
...@@ -60,23 +60,33 @@ def commit_default_branch(project, branches) ...@@ -60,23 +60,33 @@ def commit_default_branch(project, branches)
branches.include?(project.default_branch) ? branches.delete(project.default_branch) : branches.pop branches.include?(project.default_branch) ? branches.delete(project.default_branch) : branches.pop
end 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 # Returns the sorted alphabetically links to branches, separated by a comma
def commit_branches_links(project, branches) def commit_branches_links(project, branches)
branches.sort.map do |branch| branches.sort.map do |branch|
link_to(project_ref_path(project, branch), class: "label label-gray ref-name") do commit_branch_link(project_ref_path(project, branch), branch)
icon('code-fork') + " #{branch}" end.join(' ').html_safe
end end
end.join(" ").html_safe
# 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 end
# Returns the sorted links to tags, separated by a comma # Returns the sorted links to tags, separated by a comma
def commit_tags_links(project, tags) def commit_tags_links(project, tags)
sorted = VersionSorter.rsort(tags) sorted = VersionSorter.rsort(tags)
sorted.map do |tag| sorted.map do |tag|
link_to(project_ref_path(project, tag), class: "label label-gray ref-name") do commit_tag_link(project_ref_path(project, tag), tag)
icon('tag') + " #{tag}" end.join(' ').html_safe
end
end.join(" ").html_safe
end end
def link_to_browse_code(project, commit) def link_to_browse_code(project, commit)
......
...@@ -715,12 +715,12 @@ def refs_contains_sha(ref_type, sha) ...@@ -715,12 +715,12 @@ def refs_contains_sha(ref_type, sha)
end end
end end
def branch_names_contains(sha, limit = nil) def branch_names_contains(sha)
limit && branch_count > limit ? [] : refs_contains_sha('branch', sha) refs_contains_sha('branch', sha)
end end
def tag_names_contains(sha, limit = nil) def tag_names_contains(sha)
limit && tag_count > limit ? [] : refs_contains_sha('tag', sha) refs_contains_sha('tag', sha)
end end
def local_branches def local_branches
......
- if @branches.any? || @tags.any? - if @branches.any?
- branch = commit_default_branch(@project, @branches) - branch = commit_default_branch(@project, @branches)
= link_to(project_ref_path(@project, branch), class: "label label-gray ref-name") do - if branch == :limit_exceeded
= icon('code-fork') = commit_branch_link('#', _('Too many branches to search'))
= branch - else
= commit_branch_link(project_ref_path(@project, branch), branch)
-# `commit_default_branch` deletes the default branch from `@branches`, -# `commit_default_branch` deletes the default branch from `@branches`,
-# so only render this if we have more branches left -# so only render this if we have more branches or tags left
- if @branches.any? || @tags.any? - if @branches.any? || @tags.any?
%span %span
= link_to "…", "#", class: "js-details-expand label label-gray" = link_to "…", "#", class: "js-details-expand label label-gray"
%span.js-details-content.hide %span.js-details-content.hide
= commit_branches_links(@project, @branches) if @branches.any? = commit_branches_links(@project, @branches) if @branches.any?
= commit_tags_links(@project, @tags) if @tags.any? - if @tags.first == :limit_exceeded
= commit_tag_link('#', _('Too many tags to search'))
- elsif @tags.any?
= commit_tags_links(@project, @tags)
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