Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bulk_imports/users_mapper.rb')
-rw-r--r--lib/bulk_imports/users_mapper.rb41
1 files changed, 32 insertions, 9 deletions
diff --git a/lib/bulk_imports/users_mapper.rb b/lib/bulk_imports/users_mapper.rb
index 74412bc3831..af002c67367 100644
--- a/lib/bulk_imports/users_mapper.rb
+++ b/lib/bulk_imports/users_mapper.rb
@@ -6,17 +6,17 @@ module BulkImports
SOURCE_USER_IDS_CACHE_KEY = 'bulk_imports/%{bulk_import}/%{entity}/source_user_ids'
+ SOURCE_USERNAMES_CACHE_KEY = 'bulk_imports/%{bulk_import}/%{entity}/source_usernames'
+
def initialize(context:)
@context = context
- @cache_key = SOURCE_USER_IDS_CACHE_KEY % {
- bulk_import: @context.bulk_import.id,
- entity: @context.entity.id
- }
+ @user_ids_cache_key = generate_cache_key(SOURCE_USER_IDS_CACHE_KEY)
+ @usernames_cache_key = generate_cache_key(SOURCE_USERNAMES_CACHE_KEY)
end
def map
strong_memoize(:map) do
- map = hash_with_default
+ map = Hash.new { default_user_id }
cached_source_user_ids.each_pair do |source_id, destination_id|
map[source_id.to_i] = destination_id.to_i
@@ -26,6 +26,18 @@ module BulkImports
end
end
+ def map_usernames
+ strong_memoize(:map_usernames) do
+ map = {}
+
+ cached_source_usernames.each_pair do |source_username, destination_username|
+ map[source_username] = destination_username
+ end
+
+ map
+ end
+ end
+
def include?(source_user_id)
map.has_key?(source_user_id)
end
@@ -35,17 +47,28 @@ module BulkImports
end
def cache_source_user_id(source_id, destination_id)
- ::Gitlab::Cache::Import::Caching.hash_add(@cache_key, source_id, destination_id)
+ ::Gitlab::Cache::Import::Caching.hash_add(@user_ids_cache_key, source_id, destination_id)
+ end
+
+ def cache_source_username(source_username, destination_username)
+ ::Gitlab::Cache::Import::Caching.hash_add(@usernames_cache_key, source_username, destination_username)
end
private
- def hash_with_default
- Hash.new { default_user_id }
+ def generate_cache_key(pattern)
+ pattern % {
+ bulk_import: @context.bulk_import.id,
+ entity: @context.entity.id
+ }
end
def cached_source_user_ids
- ::Gitlab::Cache::Import::Caching.values_from_hash(@cache_key)
+ ::Gitlab::Cache::Import::Caching.values_from_hash(@user_ids_cache_key)
+ end
+
+ def cached_source_usernames
+ ::Gitlab::Cache::Import::Caching.values_from_hash(@usernames_cache_key)
end
end
end