Commit 7abd7d2d authored by Gary Holtz's avatar Gary Holtz

Skip keep_around commit callback if `skip_keep_around_commits` is true

Changelog: performance
parent a55c2106
...@@ -149,7 +149,7 @@ class Note < ApplicationRecord ...@@ -149,7 +149,7 @@ class Note < ApplicationRecord
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) }
before_validation :nullify_blank_type, :nullify_blank_line_code before_validation :nullify_blank_type, :nullify_blank_line_code
after_save :keep_around_commit, if: :for_project_noteable?, unless: :importing? after_save :keep_around_commit, if: :for_project_noteable?, unless: -> { importing? || skip_keep_around_commits }
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?
after_destroy :expire_etag_cache after_destroy :expire_etag_cache
......
...@@ -108,6 +108,17 @@ RSpec.describe Note do ...@@ -108,6 +108,17 @@ RSpec.describe Note do
end end
describe 'callbacks' do describe 'callbacks' do
describe '#keep_around_commit' do
it 'skips #keep_around_commit if `skip_keep_around_commits` is true ' do
noteable = create(:issue)
note = build(:note, project: noteable.project, noteable: noteable, skip_keep_around_commits: true)
expect(note).not_to receive(:keep_around_commit)
note.save!
end
end
describe '#notify_after_create' do describe '#notify_after_create' do
it 'calls #after_note_created on the noteable' do it 'calls #after_note_created on the noteable' do
noteable = create(:issue) noteable = create(:issue)
......
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