summaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-05-07 19:29:55 +0000
committerDouwe Maan <douwe@gitlab.com>2015-05-07 19:29:55 +0000
commitf5f097b765e6401ad379e313b4c34cd37d248930 (patch)
treed6cfd9e1be1d0b4ca55928f533124097940c6656 /app/helpers
parent415648e2555e25d30f64f4c2642cf149f6965859 (diff)
parentaffd049dc4427d749b97eaee37a5d54873016657 (diff)
downloadgitlab-ce-f5f097b765e6401ad379e313b4c34cd37d248930.tar.gz
Merge branch 'feature/handle-big-diffs' into 'master'
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. See merge request !539
Diffstat (limited to 'app/helpers')
-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?