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

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
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
......
......@@ -60,23 +60,33 @@ def commit_default_branch(project, branches)
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)
......
......@@ -715,12 +715,12 @@ def refs_contains_sha(ref_type, sha)
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
......
- 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)
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