optimize show_diff_size_warning?

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-09-08 22:12:54 +03:00
parent 218219abbd
commit 02e87d9223
No known key found for this signature in database
GPG key ID: 627C5F589F467F17
3 changed files with 11 additions and 6 deletions

View file

@ -1,16 +1,20 @@
module DiffHelper
def safe_diff_files(diffs)
def allowed_diff_size
if diff_hard_limit_enabled?
diffs.first(Commit::DIFF_HARD_LIMIT_FILES)
Commit::DIFF_HARD_LIMIT_FILES
else
diffs.first(Commit::DIFF_SAFE_FILES)
end.map do |diff|
Commit::DIFF_SAFE_FILES
end
end
def safe_diff_files(diffs)
diffs.first(allowed_diff_size).map do |diff|
Gitlab::Diff::File.new(diff)
end
end
def show_diff_size_warninig?(diffs)
safe_diff_files(diffs).size < diffs.size
diffs.size > allowed_diff_size
end
def diff_hard_limit_enabled?

View file

@ -11,6 +11,7 @@
- params_copy[:view] = 'inline'
= link_to "Inline Diff", url_for(params_copy), {id: "commit-diff-viewtype"}
- if show_diff_size_warninig?(diffs)
= render 'projects/diffs/warning', diffs: diffs

View file

@ -14,6 +14,6 @@
= link_to "Email patch", project_merge_request_path(@project, @merge_request, format: :patch), class: "btn btn-warning btn-small"
%p
To preserve performance only
%strong #{safe_diff_files(@project, diffs).size} of #{diffs.size}
%strong #{allowed_diff_size} of #{diffs.size}
files displayed.