Commit d11191f1 authored by Stan Hu's avatar Stan Hu

Disable creating user mentions during import

Creating a note causes a subtransaction every time `CacheMarkdownField`
attempts to refresh the issuable's user mentions. We disable it for now
to avoid large number of SQL queries. We are not using this table at the
moment for reads. https://gitlab.com/gitlab-org/gitlab/-/issues/21801
tracks the work necessary to make this work.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/336788

Changelog: performance
parent d26b12d6
......@@ -10,7 +10,9 @@ module Gitlab
# Using before_update here conflicts with elasticsearch-model somehow
before_create :refresh_markdown_cache, if: :invalidated_markdown_cache?
before_update :refresh_markdown_cache, if: :invalidated_markdown_cache?
after_save :store_mentions!, if: :mentionable_attributes_changed?
# The import case needs to be fixed to avoid large number of
# SQL queries: https://gitlab.com/gitlab-org/gitlab/-/issues/21801
after_save :store_mentions!, if: :mentionable_attributes_changed?, unless: ->(obj) { obj.is_a?(Importable) && obj.importing? }
end
# Always exclude _html fields from attributes (including serialization).
......
......@@ -178,4 +178,42 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
thing.refresh_markdown_cache!
end
end
context 'with note' do
let(:klass) do
Class.new(ActiveRecord::Base) do
self.table_name = 'notes'
include CacheMarkdownField
include Importable
include Mentionable
attr_mentionable :note, pipeline: :note
cache_markdown_field :note, pipeline: :note
end
end
let(:thing) { klass.new(note: markdown) }
before do
thing.note = "hello world"
end
it 'calls store_mentions!' do
expect(thing).to receive(:store_mentions!).and_call_original
thing.save!
end
context 'during import' do
before do
thing.importing = true
end
it 'does not call store_mentions!' do
expect(thing).not_to receive(:store_mentions!)
thing.save!
end
end
end
end
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