Class: Gitlab::BackgroundMigration::MoveCiBuildsMetadata::BulkJobDefinitionsCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/move_ci_builds_metadata.rb

Overview

This class is handed an array of not persisted job definitions and returns an unique array of persisted definitions containing only the required attributes for the migration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(migration, definitions) ⇒ BulkJobDefinitionsCreator

Returns a new instance of BulkJobDefinitionsCreator.



356
357
358
359
# File 'lib/gitlab/background_migration/move_ci_builds_metadata.rb', line 356

def initialize(migration, definitions)
  @migration = migration
  @job_definitions = definitions.uniq(&:global_identifier)
end

Instance Attribute Details

#job_definitionsObject (readonly)

Returns the value of attribute job_definitions.



352
353
354
# File 'lib/gitlab/background_migration/move_ci_builds_metadata.rb', line 352

def job_definitions
  @job_definitions
end

Instance Method Details

#executeObject



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/gitlab/background_migration/move_ci_builds_metadata.rb', line 361

def execute
  return [] if job_definitions.empty?

  existing_definitions = fetch_records_for(job_definitions)

  existing_definitions_by_attrs = existing_definitions.group_by(&:global_identifier)
  missing_definitions = job_definitions.reject do |d|
    existing_definitions_by_attrs[d.global_identifier]
  end

  return existing_definitions if missing_definitions.empty?

  insert_missing(missing_definitions)

  existing_definitions + fetch_records_for(missing_definitions)
end