summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2016-02-26 16:50:42 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2016-02-26 16:51:11 +0100
commit868d0821ed5ea05a279e025b99c312331b7adbad (patch)
tree43d6538676cc3b180b73672a46fcb9af5337ad93
parentad5e5da00bbc8ac81ee6380e77fc1c0a10c3ca54 (diff)
downloadgitlab-ce-868d0821ed5ea05a279e025b99c312331b7adbad.tar.gz
Refactor diff finding in Note
-rw-r--r--app/models/note.rb24
1 files changed, 10 insertions, 14 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 9515b8298f2..d80fc9f1cff 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -131,10 +131,11 @@ class Note < ActiveRecord::Base
end
def find_diff
- return nil unless noteable && (diffs = noteable.diffs(all_diffs: true)).present?
+ return nil unless noteable
+ return @diff if defined?(@diff)
- @diff ||= diffs.find do |d|
- Digest::SHA1.hexdigest(d.new_path) == diff_file_index if d.new_path
+ @diff = notable.diffs(Commit.max_diff_options).find do |d|
+ Digest::SHA1.hexdigest(d.new_path) == diff_file_index
end
end
@@ -165,20 +166,15 @@ class Note < ActiveRecord::Base
def active?
return true unless self.diff
return false unless noteable
+ return @active if defined?(@active)
- noteable.diffs(all_diffs: true).each do |mr_diff|
- next unless mr_diff.new_path == self.diff.new_path
+ diffs = noteable.diffs(Commit.max_diff_options)
+ notable_diff = diffs.find { |d| d.new_path == self.diff.new_path }
- lines = Gitlab::Diff::Parser.new.parse(mr_diff.diff.lines.to_a)
+ return @active = false if notable_diff.nil?
- lines.each do |line|
- if line.text == diff_line
- return true
- end
- end
- end
-
- false
+ parsed_lines = Gitlab::Diff::Parser.new.parse(notable_diff.diff.lines)
+ @active = parsed_lines.any? { |line_obj| line_obj.text == diff_line }
end
def outdated?