From 868d0821ed5ea05a279e025b99c312331b7adbad Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 26 Feb 2016 16:50:42 +0100 Subject: Refactor diff finding in Note --- app/models/note.rb | 24 ++++++++++-------------- 1 file 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? -- cgit v1.2.1