summaryrefslogtreecommitdiff
path: root/app/helpers/diff_helper.rb
diff options
context:
space:
mode:
authorAlex Lossent <alexandre.lossent@cern.ch>2015-04-27 18:06:51 +0200
committerAlex Lossent <alexandre.lossent@cern.ch>2015-05-05 18:51:12 +0200
commitaffd049dc4427d749b97eaee37a5d54873016657 (patch)
tree94541bfb05f098f67cf11d72eede4791d6e5b801 /app/helpers/diff_helper.rb
parent5bff135fb3dbd1af855f8cd94b4bed76d2cbc42e (diff)
downloadgitlab-ce-affd049dc4427d749b97eaee37a5d54873016657.tar.gz
Improve handling of large diffs
Diffs with a large number of changed lines time out (504 HTTP error) or generate a HTML page that's so heavy web browsers struggle with it. https://github.com/gitlabhq/gitlabhq/pull/5014 introduced limits on commit line count so that only a safe portion is rendered. This was later undone by code refactoring in be5b6db8, e0eb4803 and c741fcab. This patch re-introduces a safe limit on number of lines.
Diffstat (limited to 'app/helpers/diff_helper.rb')
-rw-r--r--app/helpers/diff_helper.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb
index 162778ade58..1b10795bb7b 100644
--- a/app/helpers/diff_helper.rb
+++ b/app/helpers/diff_helper.rb
@@ -7,14 +7,23 @@ module DiffHelper
end
end
- def safe_diff_files(diffs)
- diffs.first(allowed_diff_size).map do |diff|
- Gitlab::Diff::File.new(diff)
+ def allowed_diff_lines
+ if diff_hard_limit_enabled?
+ Commit::DIFF_HARD_LIMIT_LINES
+ else
+ Commit::DIFF_SAFE_LINES
end
end
- def show_diff_size_warning?(diffs)
- diffs.size > allowed_diff_size
+ def safe_diff_files(diffs)
+ lines = 0
+ safe_files = []
+ diffs.first(allowed_diff_size).each do |diff|
+ lines += diff.diff.lines.count
+ break if lines > allowed_diff_lines
+ safe_files << Gitlab::Diff::File.new(diff)
+ end
+ safe_files
end
def diff_hard_limit_enabled?