optimize show_diff_size_warning?
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
218219abbd
commit
02e87d9223
3 changed files with 11 additions and 6 deletions
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in a new issue