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

user_from_mention.rb « import « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e3489f91b419452ea0f8a3f0da6008cbabac7e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module Gitlab
  module Import
    module UserFromMention
      SOURCE_USER_CACHE_KEY = '%s/project/%s/source/username/%s'

      def user_from_cache(mention)
        cached_email = read(mention)

        return unless cached_email

        find_user(cached_email)
      end

      def cache_multiple(hash)
        ::Gitlab::Cache::Import::Caching.write_multiple(hash, timeout: timeout)
      end

      def source_user_cache_key(importer, project_id, username)
        format(SOURCE_USER_CACHE_KEY, importer, project_id, username)
      end

      private

      def read(mention)
        ::Gitlab::Cache::Import::Caching.read(source_user_cache_key(importer, project_id, mention))
      end

      def find_user(email)
        User.find_by_any_email(email, confirmed: true)
      end

      def timeout
        ::Gitlab::Cache::Import::Caching::LONGER_TIMEOUT
      end
    end
  end
end