Commit 26d31d54 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'remove-note-after-initialize' into 'master'

Remove after_initialize, before_validation for discussion_id on Note

See merge request gitlab-org/gitlab!22128
parents 4136a334 ffd53c56
...@@ -152,9 +152,7 @@ class Note < ApplicationRecord ...@@ -152,9 +152,7 @@ class Note < ApplicationRecord
scope :for_note_or_capitalized_note, ->(text) { where(note: [text, text.capitalize]) } scope :for_note_or_capitalized_note, ->(text) { where(note: [text, text.capitalize]) }
scope :like_note_or_capitalized_note, ->(text) { where('(note LIKE ? OR note LIKE ?)', text, text.capitalize) } scope :like_note_or_capitalized_note, ->(text) { where('(note LIKE ? OR note LIKE ?)', text, text.capitalize) }
after_initialize :ensure_discussion_id
before_validation :nullify_blank_type, :nullify_blank_line_code before_validation :nullify_blank_type, :nullify_blank_line_code
before_validation :set_discussion_id, on: :create
after_save :keep_around_commit, if: :for_project_noteable?, unless: :importing? after_save :keep_around_commit, if: :for_project_noteable?, unless: :importing?
after_save :expire_etag_cache, unless: :importing? after_save :expire_etag_cache, unless: :importing?
after_save :touch_noteable, unless: :importing? after_save :touch_noteable, unless: :importing?
...@@ -394,7 +392,7 @@ class Note < ApplicationRecord ...@@ -394,7 +392,7 @@ class Note < ApplicationRecord
# See `Discussion.override_discussion_id` for details. # See `Discussion.override_discussion_id` for details.
def discussion_id(noteable = nil) def discussion_id(noteable = nil)
discussion_class(noteable).override_discussion_id(self) || super() discussion_class(noteable).override_discussion_id(self) || super() || ensure_discussion_id
end end
# Returns a discussion containing just this note. # Returns a discussion containing just this note.
...@@ -533,17 +531,13 @@ class Note < ApplicationRecord ...@@ -533,17 +531,13 @@ class Note < ApplicationRecord
end end
def ensure_discussion_id def ensure_discussion_id
return unless self.persisted? return if self.attribute_present?(:discussion_id)
# Needed in case the SELECT statement doesn't ask for `discussion_id`
return unless self.has_attribute?(:discussion_id)
return if self.discussion_id
set_discussion_id self.discussion_id = derive_discussion_id
update_column(:discussion_id, self.discussion_id)
end end
def set_discussion_id def derive_discussion_id
self.discussion_id ||= discussion_class.discussion_id(self) discussion_class.discussion_id(self)
end end
def all_referenced_mentionables_allowed?(user) def all_referenced_mentionables_allowed?(user)
......
---
title: Remove after_initialize and before_validation for Note
merge_request: 22128
author:
type: performance
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment