Commit 02e87d92 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

optimize show_diff_size_warning?

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 218219ab
module DiffHelper module DiffHelper
def safe_diff_files(diffs) def allowed_diff_size
if diff_hard_limit_enabled? if diff_hard_limit_enabled?
diffs.first(Commit::DIFF_HARD_LIMIT_FILES) Commit::DIFF_HARD_LIMIT_FILES
else else
diffs.first(Commit::DIFF_SAFE_FILES) Commit::DIFF_SAFE_FILES
end.map do |diff| end
end
def safe_diff_files(diffs)
diffs.first(allowed_diff_size).map do |diff|
Gitlab::Diff::File.new(diff) Gitlab::Diff::File.new(diff)
end end
end end
def show_diff_size_warninig?(diffs) def show_diff_size_warninig?(diffs)
safe_diff_files(diffs).size < diffs.size diffs.size > allowed_diff_size
end end
def diff_hard_limit_enabled? def diff_hard_limit_enabled?
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
- params_copy[:view] = 'inline' - params_copy[:view] = 'inline'
= link_to "Inline Diff", url_for(params_copy), {id: "commit-diff-viewtype"} = link_to "Inline Diff", url_for(params_copy), {id: "commit-diff-viewtype"}
- if show_diff_size_warninig?(diffs) - if show_diff_size_warninig?(diffs)
= render 'projects/diffs/warning', diffs: diffs = render 'projects/diffs/warning', diffs: diffs
......
...@@ -14,6 +14,6 @@ ...@@ -14,6 +14,6 @@
= link_to "Email patch", project_merge_request_path(@project, @merge_request, format: :patch), class: "btn btn-warning btn-small" = link_to "Email patch", project_merge_request_path(@project, @merge_request, format: :patch), class: "btn btn-warning btn-small"
%p %p
To preserve performance only To preserve performance only
%strong #{safe_diff_files(@project, diffs).size} of #{diffs.size} %strong #{allowed_diff_size} of #{diffs.size}
files displayed. files displayed.
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