summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-29 09:08:49 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-29 09:08:49 +0000
commit46b10c0fc884400941c17e2777b242ac54d111e5 (patch)
tree184bc49764f03791610c8ae716c03e0100ed45f5 /lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb
parent3358e1fdb8fe1e8f739024ee4f3d1071b296a010 (diff)
downloadgitlab-ce-46b10c0fc884400941c17e2777b242ac54d111e5.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb')
-rw-r--r--lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb b/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb
new file mode 100644
index 00000000000..e951b44b036
--- /dev/null
+++ b/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+# rubocop:disable Style/Documentation
+
+module Gitlab
+ module BackgroundMigration
+ module UserMentions
+ class CreateResourceUserMention
+ # Resources that have mentions to be migrated:
+ # issue, merge_request, epic, commit, snippet, design
+
+ BULK_INSERT_SIZE = 5000
+ ISOLATION_MODULE = 'Gitlab::BackgroundMigration::UserMentions::Models'
+
+ def perform(resource_model, join, conditions, with_notes, start_id, end_id)
+ resource_model = "#{ISOLATION_MODULE}::#{resource_model}".constantize if resource_model.is_a?(String)
+ model = with_notes ? "#{ISOLATION_MODULE}::Note".constantize : resource_model
+ resource_user_mention_model = resource_model.user_mention_model
+
+ records = model.joins(join).where(conditions).where(id: start_id..end_id)
+
+ records.in_groups_of(BULK_INSERT_SIZE, false).each do |records|
+ mentions = []
+ records.each do |record|
+ mentions << record.build_mention_values
+ end
+
+ no_quote_columns = [:note_id]
+ no_quote_columns << resource_user_mention_model.resource_foreign_key
+
+ Gitlab::Database.bulk_insert(
+ resource_user_mention_model.table_name,
+ mentions,
+ return_ids: true,
+ disable_quote: no_quote_columns,
+ on_conflict: :do_nothing
+ )
+ end
+ end
+ end
+ end
+ end
+end