diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /lib/bulk_imports/users_mapper.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'lib/bulk_imports/users_mapper.rb')
-rw-r--r-- | lib/bulk_imports/users_mapper.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/bulk_imports/users_mapper.rb b/lib/bulk_imports/users_mapper.rb new file mode 100644 index 00000000000..74412bc3831 --- /dev/null +++ b/lib/bulk_imports/users_mapper.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module BulkImports + class UsersMapper + include Gitlab::Utils::StrongMemoize + + SOURCE_USER_IDS_CACHE_KEY = 'bulk_imports/%{bulk_import}/%{entity}/source_user_ids' + + def initialize(context:) + @context = context + @cache_key = SOURCE_USER_IDS_CACHE_KEY % { + bulk_import: @context.bulk_import.id, + entity: @context.entity.id + } + end + + 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 + + def include?(source_user_id) + map.has_key?(source_user_id) + end + + def default_user_id + @context.current_user.id + end + + def cache_source_user_id(source_id, destination_id) + ::Gitlab::Cache::Import::Caching.hash_add(@cache_key, source_id, destination_id) + end + + private + + def hash_with_default + Hash.new { default_user_id } + end + + def cached_source_user_ids + ::Gitlab::Cache::Import::Caching.values_from_hash(@cache_key) + end + end +end |