diff options
author | Robert Speicher <robert@gitlab.com> | 2017-12-22 18:04:27 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-12-22 18:04:27 +0000 |
commit | 255e64ef61b7f1555db1230d099095642e1dcc46 (patch) | |
tree | 37677c9c31f72a9e0f11589446940ba8ef7411da /app | |
parent | 8a488a02ce9cf6ea6cbddbb57991548e35cb3a0c (diff) | |
parent | 771bf9527ffd5fd8fe258381593f686d5d960a42 (diff) | |
download | gitlab-ce-255e64ef61b7f1555db1230d099095642e1dcc46.tar.gz |
Merge branch 'dm-diff-note-for-line-performance' into 'master'
Improve performance of DiffDiscussion#truncated_diff_lines and DiffNote#diff_line by removing expensive diff position calculation and comparison
Closes #41406
See merge request gitlab-org/gitlab-ce!16111
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/discussion_on_diff.rb | 10 | ||||
-rw-r--r-- | app/models/concerns/note_on_diff.rb | 4 | ||||
-rw-r--r-- | app/models/diff_note.rb | 6 | ||||
-rw-r--r-- | app/models/legacy_diff_note.rb | 6 |
4 files changed, 6 insertions, 20 deletions
diff --git a/app/models/concerns/discussion_on_diff.rb b/app/models/concerns/discussion_on_diff.rb index 4b4d519f3df..db9770fabf4 100644 --- a/app/models/concerns/discussion_on_diff.rb +++ b/app/models/concerns/discussion_on_diff.rb @@ -9,7 +9,6 @@ module DiscussionOnDiff :original_line_code, :diff_file, :diff_line, - :for_line?, :active?, :created_at_diff?, @@ -39,17 +38,16 @@ module DiscussionOnDiff # Returns an array of at most 16 highlighted lines above a diff note def truncated_diff_lines(highlight: true) lines = highlight ? highlighted_diff_lines : diff_lines + + initial_line_index = [diff_line.index - NUMBER_OF_TRUNCATED_DIFF_LINES + 1, 0].max + prev_lines = [] - lines.each do |line| + lines[initial_line_index..diff_line.index].each do |line| if line.meta? prev_lines.clear else prev_lines << line - - break if for_line?(line) - - prev_lines.shift if prev_lines.length >= NUMBER_OF_TRUNCATED_DIFF_LINES end end diff --git a/app/models/concerns/note_on_diff.rb b/app/models/concerns/note_on_diff.rb index f734952fa6c..510b8868462 100644 --- a/app/models/concerns/note_on_diff.rb +++ b/app/models/concerns/note_on_diff.rb @@ -14,10 +14,6 @@ module NoteOnDiff raise NotImplementedError end - def for_line?(line) - raise NotImplementedError - end - def original_line_code raise NotImplementedError end diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index b53d44cda95..15122cbc693 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -21,7 +21,7 @@ class DiffNote < Note before_validation :set_original_position, on: :create before_validation :update_position, on: :create, if: :on_text? - before_validation :set_line_code + before_validation :set_line_code, if: :on_text? after_save :keep_around_commits def discussion_class(*) @@ -61,10 +61,6 @@ class DiffNote < Note @diff_line ||= diff_file&.line_for_position(self.original_position) end - def for_line?(line) - diff_file.position(line) == self.original_position - end - def original_line_code return unless on_text? diff --git a/app/models/legacy_diff_note.rb b/app/models/legacy_diff_note.rb index c36be956ff0..d90cafd14b4 100644 --- a/app/models/legacy_diff_note.rb +++ b/app/models/legacy_diff_note.rb @@ -38,11 +38,7 @@ class LegacyDiffNote < Note end def diff_line - @diff_line ||= diff_file.line_for_line_code(self.line_code) if diff_file - end - - def for_line?(line) - line.discussable? && diff_file.line_code(line) == self.line_code + @diff_line ||= diff_file&.line_for_line_code(self.line_code) end def original_line_code |