Commit 022c38e6 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Use `keys` instead of `scan_each`

parent 3899d07f
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
pattern = "#{Gitlab::Git::Storage::REDIS_KEY_PREFIX}*" pattern = "#{Gitlab::Git::Storage::REDIS_KEY_PREFIX}*"
Gitlab::Git::Storage.redis.with do |redis| Gitlab::Git::Storage.redis.with do |redis|
all_storage_keys = redis.scan_each(match: pattern).to_a all_storage_keys = redis.keys(pattern)
redis.del(*all_storage_keys) unless all_storage_keys.empty? redis.del(*all_storage_keys) unless all_storage_keys.empty?
end end
......
...@@ -14,17 +14,7 @@ module Gitlab ...@@ -14,17 +14,7 @@ module Gitlab
Gitlab::Git::Storage.redis.with do |redis| Gitlab::Git::Storage.redis.with do |redis|
keys_per_storage = all_keys_for_storages(storage_names, redis) keys_per_storage = all_keys_for_storages(storage_names, redis)
results_per_storage = load_for_keys(keys_per_storage, redis)
# We need to make sure all keys are actually loaded as an array.
# Otherwise when using the enumerator of the `scan_each` within a
# second pipeline, it will be assumed unloaded, wich would make the
# result unusable inside the pipeline.
loaded_keys_per_storage = keys_per_storage.inject({}) do |loaded_keys, (storage_name, keys)|
loaded_keys[storage_name] = keys.to_a
loaded_keys
end
results_per_storage = load_for_keys(loaded_keys_per_storage, redis)
end end
results_per_storage.map do |name, info| results_per_storage.map do |name, info|
...@@ -34,13 +24,13 @@ module Gitlab ...@@ -34,13 +24,13 @@ module Gitlab
end end
def self.all_keys_for_storages(storage_names, redis) def self.all_keys_for_storages(storage_names, redis)
keys_per_storage = nil keys_per_storage = {}
redis.pipelined do redis.pipelined do
keys_per_storage = storage_names.inject({}) do |result, storage_name| storage_names.each do |storage_name|
key = pattern_for_storage(storage_name) pattern = pattern_for_storage(storage_name)
result.merge(storage_name => redis.scan_each(match: key)) keys_per_storage[storage_name] = redis.keys(pattern)
end end
end end
...@@ -48,15 +38,15 @@ module Gitlab ...@@ -48,15 +38,15 @@ module Gitlab
end end
def self.load_for_keys(keys_per_storage, redis) def self.load_for_keys(keys_per_storage, redis)
info_for_keys = nil info_for_keys = {}
redis.pipelined do redis.pipelined do
info_for_keys = keys_per_storage.inject({}) do |result, (storage_name, keys)| keys_per_storage.each do |storage_name, keys_future|
info_for_storage = keys.map do |key| info_for_storage = keys_future.value.map do |key|
{ name: key, failure_count: redis.hget(key, :failure_count) } { name: key, failure_count: redis.hget(key, :failure_count) }
end end
result.merge(storage_name => info_for_storage) info_for_keys[storage_name] = info_for_storage
end end
end end
......
...@@ -23,7 +23,9 @@ describe Gitlab::Git::Storage::Health, clean_gitlab_redis_shared_state: true, br ...@@ -23,7 +23,9 @@ describe Gitlab::Git::Storage::Health, clean_gitlab_redis_shared_state: true, br
describe '.load_for_keys' do describe '.load_for_keys' do
let(:subject) do let(:subject) do
results = Gitlab::Git::Storage.redis.with do |redis| results = Gitlab::Git::Storage.redis.with do |redis|
described_class.load_for_keys({ 'broken' => [host1_key] }, redis) fake_future = double
allow(fake_future).to receive(:value).and_return([host1_key])
described_class.load_for_keys({ 'broken' => fake_future }, redis)
end end
# Make sure the `Redis#future is loaded # Make sure the `Redis#future is loaded
......
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