Class: Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMention
- Inherits:
-
Object
- Object
- Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMention
- Defined in:
- lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb
Constant Summary collapse
- BULK_INSERT_SIZE =
Resources that have mentions to be migrated: issue, merge_request, epic, commit, snippet, design
1_000
- ISOLATION_MODULE =
'Gitlab::BackgroundMigration::UserMentions::Models'
Instance Method Summary collapse
Instance Method Details
#perform(resource_model, join, conditions, with_notes, start_id, end_id) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb', line 14 def perform(resource_model, join, conditions, with_notes, start_id, end_id) return unless Feature.enabled?(:migrate_user_mentions, default_enabled: true) resource_model = "#{ISOLATION_MODULE}::#{resource_model}".constantize if resource_model.is_a?(String) model = with_notes ? Gitlab::BackgroundMigration::UserMentions::Models::Note : resource_model resource_user_mention_model = resource_model.user_mention_model records = model.joins(join).where(conditions).where(id: start_id..end_id) records.each_batch(of: BULK_INSERT_SIZE) do |records| mentions = [] records.each do |record| mention_record = record.build_mention_values(resource_user_mention_model.resource_foreign_key) mentions << mention_record unless mention_record.blank? end resource_user_mention_model.insert_all(mentions) unless mentions.empty? end end |