Class: Gitlab::BackgroundMigration::BackfillMemberNamespaceForGroupMembers

Inherits:
Object
  • Object
show all
Includes:
Database::DynamicModelHelpers
Defined in:
lib/gitlab/background_migration/backfill_member_namespace_for_group_members.rb

Overview

Backfills the ‘members.member_namespace_id` column for `type=GroupMember`

Constant Summary

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods included from Database::DynamicModelHelpers

#define_batchable_model, #each_batch, #each_batch_range

Instance Method Details

#batch_metricsObject



22
23
24
# File 'lib/gitlab/background_migration/backfill_member_namespace_for_group_members.rb', line 22

def batch_metrics
  @batch_metrics ||= Gitlab::Database::BackgroundMigration::BatchMetrics.new
end

#perform(start_id, end_id, batch_table, batch_column, sub_batch_size, pause_ms) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gitlab/background_migration/backfill_member_namespace_for_group_members.rb', line 9

def perform(start_id, end_id, batch_table, batch_column, sub_batch_size, pause_ms)
  parent_batch_relation = relation_scoped_to_range(batch_table, batch_column, start_id, end_id)

  parent_batch_relation.each_batch(column: batch_column, of: sub_batch_size) do |sub_batch|
    batch_metrics.time_operation(:update_all) do
      sub_batch.update_all('member_namespace_id=source_id')
    end

    pause_ms = [0, pause_ms].max
    sleep(pause_ms * 0.001)
  end
end