Class: Gitlab::BackgroundMigration::BackfillMissingNamespaceIdOnNotes
- Inherits:
-
BatchedMigrationJob
- Object
- BatchedMigrationJob
- Gitlab::BackgroundMigration::BackfillMissingNamespaceIdOnNotes
- Defined in:
- lib/gitlab/background_migration/backfill_missing_namespace_id_on_notes.rb
Overview
rubocop:disable Metrics/ClassLength – Background migration requires multiple resolution strategies for different noteable types
Constant Summary
Constants inherited from BatchedMigrationJob
Gitlab::BackgroundMigration::BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY, Gitlab::BackgroundMigration::BatchedMigrationJob::MINIMUM_PAUSE_MS
Constants included from Database::DynamicModelHelpers
Database::DynamicModelHelpers::BATCH_SIZE
Instance Method Summary collapse
Methods inherited from BatchedMigrationJob
#batch_metrics, cursor, cursor?, cursor_columns, feature_category, #filter_batch, generic_instance, health_context_tables, #initialize, job_arguments, job_arguments_count, operation_name, scope_to, tables_to_check_for_vacuum
Methods included from Database::DynamicModelHelpers
define_batchable_model, #each_batch, #each_batch_range
Constructor Details
This class inherits a constructor from Gitlab::BackgroundMigration::BatchedMigrationJob
Instance Method Details
#perform ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gitlab/background_migration/backfill_missing_namespace_id_on_notes.rb', line 13 def perform each_sub_batch do |sub_batch| # Build common CTEs that will be reused for all update queries ctes = build_common_ctes(sub_batch) # Get distinct noteable types in this batch to avoid unnecessary queries noteable_types = fetch_noteable_types_in_batch(ctes) # Skip processing if no notes need updating next if noteable_types.empty? # Process only the noteable types that exist in this batch process_noteables_with_ctes(ctes, noteable_types) # Archive orphaned notes (those still without namespace_id) archive_orphaned_notes_with_ctes(ctes) end end |