summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2019-09-02 14:15:16 +0000
committerDouwe Maan <douwe@gitlab.com>2019-09-02 14:15:16 +0000
commit68bfb091ae3c4b3885a1e8be09b347f26c8a3a00 (patch)
treee08e2fc2129b645d5f89ca8f378a1307aba6b136 /app
parent1a060f7dca85cf5bb9950f3ce944f0b5a287ac2a (diff)
parentbf230da05d8a3a6feeeb80d81fa0370cc295478e (diff)
downloadgitlab-ce-68bfb091ae3c4b3885a1e8be09b347f26c8a3a00.tar.gz
Merge branch '65152-unfolded-lines-perf-improvement' into 'master'
Support selective highlighting of lines See merge request gitlab-org/gitlab-ce!32514
Diffstat (limited to 'app')
-rw-r--r--app/presenters/blob_presenter.rb18
-rw-r--r--app/presenters/blobs/unfold_presenter.rb8
2 files changed, 19 insertions, 7 deletions
diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb
index 2cf3278d240..3a71d2b87f3 100644
--- a/app/presenters/blob_presenter.rb
+++ b/app/presenters/blob_presenter.rb
@@ -3,12 +3,12 @@
class BlobPresenter < Gitlab::View::Presenter::Delegated
presents :blob
- def highlight(plain: nil)
+ def highlight(to: nil, plain: nil)
load_all_blob_data
Gitlab::Highlight.highlight(
blob.path,
- blob.data,
+ limited_blob_data(to: to),
language: blob.language_from_gitattributes,
plain: plain
)
@@ -23,4 +23,18 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
def load_all_blob_data
blob.load_all_data! if blob.respond_to?(:load_all_data!)
end
+
+ def limited_blob_data(to: nil)
+ return blob.data if to.blank?
+
+ # Even though we don't need all the lines at the start of the file (e.g
+ # viewing the middle part of a file), they still need to be highlighted
+ # to ensure that the succeeding lines can be formatted correctly (e.g.
+ # multi-line comments).
+ all_lines[0..to - 1].join
+ end
+
+ def all_lines
+ @all_lines ||= blob.data.lines
+ end
end
diff --git a/app/presenters/blobs/unfold_presenter.rb b/app/presenters/blobs/unfold_presenter.rb
index a256dd05a4d..487c6fe0757 100644
--- a/app/presenters/blobs/unfold_presenter.rb
+++ b/app/presenters/blobs/unfold_presenter.rb
@@ -26,8 +26,6 @@ module Blobs
# so we can accurately show the rest of the diff when unfolding.
load_all_blob_data
- @all_lines = blob.data.lines
-
handle_full_or_end!
end
@@ -46,7 +44,7 @@ module Blobs
def lines
strong_memoize(:lines) do
- limit(highlight.lines).map(&:html_safe)
+ limit(highlight(to: to).lines).map(&:html_safe)
end
end
@@ -76,7 +74,7 @@ module Blobs
def all_lines_size
strong_memoize(:all_lines_size) do
- @all_lines.size
+ all_lines.size
end
end
@@ -101,7 +99,7 @@ module Blobs
def limited_blob_lines
strong_memoize(:limited_blob_lines) do
- limit(@all_lines)
+ limit(all_lines)
end
end