Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-08-17 20:14:44 +0300
committerDouwe Maan <douwe@selenight.nl>2016-08-17 20:16:46 +0300
commit4a13aa9f34ab4114bc485e1ca8fa0db8daa0394b (patch)
tree17554a901009603f52be08914636495b06db2e68 /app/models/diff_note.rb
parentf3acf9fd248a16665a114bf6cce761e9277c2d5b (diff)
Store discussion_id on Note for faster discussion lookup.
Diffstat (limited to 'app/models/diff_note.rb')
-rw-r--r--app/models/diff_note.rb37
1 files changed, 23 insertions, 14 deletions
diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb
index cfcdce790e5..1313739f322 100644
--- a/app/models/diff_note.rb
+++ b/app/models/diff_note.rb
@@ -15,8 +15,9 @@ class DiffNote < Note
validate :positions_complete
validate :verify_supported
+ after_initialize :ensure_original_discussion_id
before_validation :set_original_position, :update_position, on: :create
- before_validation :set_line_code
+ before_validation :set_line_code, :set_original_discussion_id
after_save :keep_around_commits
class << self
@@ -33,14 +34,6 @@ class DiffNote < Note
{ position: position.to_json }
end
- def discussion_id
- @discussion_id ||= Digest::SHA1.hexdigest(self.class.build_discussion_id(noteable_type, noteable_id || commit_id, position))
- end
-
- def original_discussion_id
- @original_discussion_id ||= Digest::SHA1.hexdigest(self.class.build_discussion_id(noteable_type, noteable_id || commit_id, original_position))
- end
-
def position=(new_position)
if new_position.is_a?(String)
new_position = JSON.parse(new_position) rescue nil
@@ -106,11 +99,7 @@ class DiffNote < Note
def discussion
return unless resolvable?
- discussion_notes = self.noteable.notes.fresh.select { |n| n.discussion_id == self.discussion_id }
-
- return if discussion_notes.empty?
-
- Discussion.new(discussion_notes)
+ self.noteable.find_diff_discussion(self.discussion_id)
end
def to_discussion
@@ -139,6 +128,26 @@ class DiffNote < Note
self.line_code = self.position.line_code(self.project.repository)
end
+ def ensure_original_discussion_id
+ return unless self.persisted?
+ return if self.original_discussion_id
+
+ set_original_discussion_id
+ update_column(:original_discussion_id, self.original_discussion_id)
+ end
+
+ def set_original_discussion_id
+ self.original_discussion_id = Digest::SHA1.hexdigest(build_original_discussion_id)
+ end
+
+ def build_discussion_id
+ self.class.build_discussion_id(noteable_type, noteable_id || commit_id, position)
+ end
+
+ def build_original_discussion_id
+ self.class.build_discussion_id(noteable_type, noteable_id || commit_id, original_position)
+ end
+
def update_position
return unless supported?
return if for_commit?