Class: BulkImports::UsersMapper

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
lib/bulk_imports/users_mapper.rb

Constant Summary collapse

SOURCE_USER_IDS_CACHE_KEY =
'bulk_imports/%{bulk_import}/%{entity}/source_user_ids'

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(context:) ⇒ UsersMapper

Returns a new instance of UsersMapper.


9
10
11
12
13
14
15
# File 'lib/bulk_imports/users_mapper.rb', line 9

def initialize(context:)
  @context = context
  @cache_key = SOURCE_USER_IDS_CACHE_KEY % {
    bulk_import: @context.bulk_import.id,
    entity: @context.entity.id
  }
end

Instance Method Details

#cache_source_user_id(source_id, destination_id) ⇒ Object


37
38
39
# File 'lib/bulk_imports/users_mapper.rb', line 37

def cache_source_user_id(source_id, destination_id)
  ::Gitlab::Cache::Import::Caching.hash_add(@cache_key, source_id, destination_id)
end

#default_user_idObject


33
34
35
# File 'lib/bulk_imports/users_mapper.rb', line 33

def default_user_id
  @context.current_user.id
end

#include?(source_user_id) ⇒ Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/bulk_imports/users_mapper.rb', line 29

def include?(source_user_id)
  map.has_key?(source_user_id)
end

#mapObject


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bulk_imports/users_mapper.rb', line 17

def map
  strong_memoize(:map) do
    map = hash_with_default

    cached_source_user_ids.each_pair do |source_id, destination_id|
      map[source_id.to_i] = destination_id.to_i
    end

    map
  end
end