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-10 06:10:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-10 06:10:59 +0300
commitdb6b854ea711b395c17827a5047f54dc29b518f9 (patch)
tree5c853b091a3a4068a3a091a33929128900c1a47b /lib/gitlab/repository_cache
parent8f8e342720899033f06747430414d2d2e3e6527a (diff)
Add latest changes from gitlab-org/gitlab@master
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