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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 16:18:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 16:18:24 +0300
commit0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch)
tree4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/gitlab/repository_cache
parent744144d28e3e7fddc117924fef88de5d9674fe4c (diff)
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'lib/gitlab/repository_cache')
-rw-r--r--lib/gitlab/repository_cache/preloader.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/gitlab/repository_cache/preloader.rb b/lib/gitlab/repository_cache/preloader.rb
new file mode 100644
index 00000000000..726dde4e0ca
--- /dev/null
+++ b/lib/gitlab/repository_cache/preloader.rb
@@ -0,0 +1,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