Class: Gitlab::ImportExport::Base::RelationObjectSaver

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/import_export/base/relation_object_saver.rb

Constant Summary collapse

BATCH_SIZE =
100
MAX_RETRY_COUNT =

Default retry count for handling ActiveRecord::QueryCanceled

3
BATCH_SIZE_REDUCTION_FACTOR =

Factor to reduce batch size by when retrying after a timeout

4
MAX_EXCEPTION_RESCUE_COUNT =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation_object:, relation_key:, relation_definition:, importable:) ⇒ RelationObjectSaver

Returns a new instance of RelationObjectSaver.

Examples:

Gitlab::ImportExport::Base::RelationObjectSaver.new(
  relation_key: 'merge_requests',
  relation_object: #<MergeRequest id: root/mrs!1, notes: [#<Note id: nil, note: 'test', ...>, #<Note id: nil, noteL 'another note'>]>,
  relation_definition: {"metrics"=>{}, "award_emoji"=>{}, "notes"=>{"author"=>{}, ... }}
  importable: @importable
).execute

Parameters:

  • relation_object (Object)

    Object of a project/group, e.g. an issue

  • relation_key (String)

    Name of the object association to group/project, e.g. :issues

  • relation_definition (Hash)

    Object subrelations as defined in import_export.yml

  • importable (Project|Group)

    Project or group where relation object is getting saved to



39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/import_export/base/relation_object_saver.rb', line 39

def initialize(relation_object:, relation_key:, relation_definition:, importable:)
  @relation_object = relation_object
  @relation_key = relation_key
  @relation_definition = relation_definition
  @importable = importable
  @invalid_subrelations = []
  @failed_subrelations = []
  @exceptions_rescued = 0
end

Instance Attribute Details

#failed_subrelationsObject (readonly)

Returns the value of attribute failed_subrelations.



25
26
27
# File 'lib/gitlab/import_export/base/relation_object_saver.rb', line 25

def failed_subrelations
  @failed_subrelations
end

#invalid_subrelationsObject (readonly)

Returns the value of attribute invalid_subrelations.



25
26
27
# File 'lib/gitlab/import_export/base/relation_object_saver.rb', line 25

def invalid_subrelations
  @invalid_subrelations
end

Instance Method Details

#executeObject



49
50
51
52
53
54
55
# File 'lib/gitlab/import_export/base/relation_object_saver.rb', line 49

def execute
  move_subrelations

  relation_object.save!

  save_subrelations
end