Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20201014142521_schedule_sync_blocking_issues_count.rb')
-rw-r--r--db/post_migrate/20201014142521_schedule_sync_blocking_issues_count.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/db/post_migrate/20201014142521_schedule_sync_blocking_issues_count.rb b/db/post_migrate/20201014142521_schedule_sync_blocking_issues_count.rb
new file mode 100644
index 00000000000..61b2b2aaad5
--- /dev/null
+++ b/db/post_migrate/20201014142521_schedule_sync_blocking_issues_count.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'set'
+
+class ScheduleSyncBlockingIssuesCount < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ BATCH_SIZE = 50
+ DELAY_INTERVAL = 120.seconds.to_i
+ MIGRATION = 'SyncBlockingIssuesCount'.freeze
+
+ disable_ddl_transaction!
+
+ class TmpIssueLink < ActiveRecord::Base
+ self.table_name = 'issue_links'
+
+ include EachBatch
+ end
+
+ def up
+ return unless Gitlab.ee?
+
+ issue_link_ids = SortedSet.new
+
+ TmpIssueLink.distinct.select(:source_id).where(link_type: 1).each_batch(of: 1000, column: :source_id) do |query|
+ issue_link_ids.merge(query.pluck(:source_id))
+ end
+
+ TmpIssueLink.distinct.select(:target_id).where(link_type: 2).each_batch(of: 1000, column: :target_id) do |query|
+ issue_link_ids.merge(query.pluck(:target_id))
+ end
+
+ issue_link_ids.each_slice(BATCH_SIZE).with_index do |items, index|
+ start_id, *, end_id = items
+
+ arguments = [start_id, end_id]
+
+ final_delay = DELAY_INTERVAL * (index + 1)
+ migrate_in(final_delay, MIGRATION, arguments)
+ end
+ end
+
+ def down
+ # NO OP
+ end
+end