Commit ad17c560 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'reverse-redis-perf-improvement' into 'master'

Revert "Improves the performance of the Redis set cache"

See merge request gitlab-org/gitlab!19573
parents f5a64c57 396f92d0
...@@ -58,16 +58,11 @@ module Gitlab ...@@ -58,16 +58,11 @@ module Gitlab
# wrong answer. We handle that by querying the full list - which fills # wrong answer. We handle that by querying the full list - which fills
# the cache - and using it directly to answer the question. # the cache - and using it directly to answer the question.
define_method("#{name}_include?") do |value| define_method("#{name}_include?") do |value|
return __send__(name).include?(value) if strong_memoized?(name) # rubocop:disable GitlabSecurity/PublicSend if strong_memoized?(name) || !redis_set_cache.exist?(name)
return __send__(name).include?(value) # rubocop:disable GitlabSecurity/PublicSend
# If the member exists in the set, return as such early. end
return true if redis_set_cache.include?(name, value)
# If it did not, make sure the collection exists.
# If the collection exists, then item does not.
return false if redis_set_cache.exist?(name)
__send__(name).include?(value) # rubocop:disable GitlabSecurity/PublicSend redis_set_cache.include?(name, value)
end end
end end
......
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
end end
def read(key) def read(key)
with { |redis| redis.sscan_each(cache_key(key)).to_a } with { |redis| redis.smembers(cache_key(key)) }
end end
def write(key, value) def write(key, value)
...@@ -47,11 +47,12 @@ module Gitlab ...@@ -47,11 +47,12 @@ module Gitlab
end end
def fetch(key, &block) def fetch(key, &block)
result = read(key) if exist?(key)
return result unless result.empty? read(key)
else
write(key, yield) write(key, yield)
end end
end
def include?(key, value) def include?(key, value)
with { |redis| redis.sismember(cache_key(key), value) } with { |redis| redis.sismember(cache_key(key), value) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment