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
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) }
after_initialize :ensure_discussion_id
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 :expire_etag_cache, unless: :importing?
after_save :touch_noteable, unless: :importing?
......@@ -394,7 +392,7 @@ class Note < ApplicationRecord
# See `Discussion.override_discussion_id` for details.
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
# Returns a discussion containing just this note.
......@@ -533,17 +531,13 @@ class Note < ApplicationRecord
end
def ensure_discussion_id
return unless self.persisted?
# Needed in case the SELECT statement doesn't ask for `discussion_id`
return unless self.has_attribute?(:discussion_id)
return if self.discussion_id
return if self.attribute_present?(:discussion_id)
set_discussion_id
update_column(:discussion_id, self.discussion_id)
self.discussion_id = derive_discussion_id
end
def set_discussion_id
self.discussion_id ||= discussion_class.discussion_id(self)
def derive_discussion_id
discussion_class.discussion_id(self)
end
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