Class: Import::ReassignPlaceholderUserRecordsService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::InternalEventsTracking
Defined in:
app/services/import/reassign_placeholder_user_records_service.rb

Constant Summary collapse

MEMBER_SELECT_BATCH_SIZE =
100
MEMBER_DELETE_BATCH_SIZE =
1_000
REFERENCE_DELETE_BATCH_SIZE =
1_000
GROUP_FINDER_MEMBER_RELATIONS =
%i[direct inherited shared_from_groups].freeze
PROJECT_FINDER_MEMBER_RELATIONS =
%i[direct inherited invited_groups shared_into_ancestors].freeze
RELATION_BATCH_SLEEP =
5

Instance Method Summary collapse

Methods included from Gitlab::InternalEventsTracking

#track_internal_event

Constructor Details

#initialize(import_source_user) ⇒ ReassignPlaceholderUserRecordsService

Returns a new instance of ReassignPlaceholderUserRecordsService.



14
15
16
17
18
19
20
# File 'app/services/import/reassign_placeholder_user_records_service.rb', line 14

def initialize(import_source_user)
  @import_source_user = import_source_user
  @reassigned_by_user = import_source_user.reassigned_by_user
  @unavailable_tables = []
  @refresh_project_access = false
  @reassignment_throttling = ReassignPlaceholderThrottling.new(import_source_user)
end

Instance Method Details

#executeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/services/import/reassign_placeholder_user_records_service.rb', line 22

def execute
  return unless import_source_user.reassignment_in_progress?

  warn_about_any_risky_reassignments

  log_warn('Reassigned by user was not found, this may affect membership checks') unless reassigned_by_user

  begin
    DirectReassignService.new(import_source_user, reassignment_throttling: reassignment_throttling).execute

    reassign_placeholder_references

    delete_remaining_references

    if placeholder_memberships.any?
      create_memberships
      delete_placeholder_memberships
    end

  rescue ReassignPlaceholderThrottling::DatabaseHealthError => error
    return handle_reschedule_error(error, :db_health_check_failed)
  rescue Gitlab::Utils::ExecutionTracker::ExecutionTimeOutError => error
    return handle_reschedule_error(error, :execution_timeout)
  end

  UserProjectAccessChangedService.new(import_source_user.reassign_to_user_id).execute if refresh_project_access?

  import_source_user.complete!

  track_reassignment_complete

  ServiceResponse.success(
    message: s_('Import|Placeholder user record reassignment complete'),
    payload: import_source_user
  )
end