diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-10 06:10:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-10 06:10:59 +0300 |
commit | db6b854ea711b395c17827a5047f54dc29b518f9 (patch) | |
tree | 5c853b091a3a4068a3a091a33929128900c1a47b /lib/gitlab | |
parent | 8f8e342720899033f06747430414d2d2e3e6527a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/repository_cache/preloader.rb | 40 | ||||
-rw-r--r-- | lib/gitlab/repository_cache_adapter.rb | 4 |
2 files changed, 44 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 diff --git a/lib/gitlab/repository_cache_adapter.rb b/lib/gitlab/repository_cache_adapter.rb index d0230c035cc..c096c870f2a 100644 --- a/lib/gitlab/repository_cache_adapter.rb +++ b/lib/gitlab/repository_cache_adapter.rb @@ -217,6 +217,10 @@ module Gitlab fallback end + def memoize_method_cache_value(method, value) + strong_memoize(memoizable_name(method)) { value } + end + # Expires the caches of a specific set of methods def expire_method_caches(methods) methods.each do |name| |