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

preloader.rb « repository_cache « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 726dde4e0ca5fdf9841d2cb147e8f2e75dc56784 (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
40
# frozen_string_literal: true

module Gitlab
  class RepositoryCache
    class Preloader
      def initialize(repositories)
        @repositories = repositories
      end

      def preload(methods)
        return if @repositories.empty?

        cache_keys = []

        sources_by_cache_key = @repositories.each_with_object({}) do |repository, hash|
          methods.each do |method|
            cache_key = repository.cache.cache_key(method)

            hash[cache_key] = { repository: repository, method: method }
            cache_keys << cache_key
          end
        end

        Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
          backend.read_multi(*cache_keys).each do |cache_key, value|
            source = sources_by_cache_key[cache_key]

            source[:repository].memoize_method_cache_value(source[:method], value)
          end
        end
      end

      private

      def backend
        @repositories.first.cache.backend
      end
    end
  end
end