From 77a416c84f6d34a62ee55af329113152d4e3b5a0 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Fri, 11 Oct 2019 13:58:24 -0400 Subject: [PATCH] Tidy and speed up ActiveSupport::Cache::Store#read_multi_entries --- activesupport/lib/active_support/cache.rb | 25 ++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 00f7c81927..f3c647d70f 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -583,23 +583,20 @@ module ActiveSupport # Reads multiple entries from the cache implementation. Subclasses MAY # implement this method. def read_multi_entries(names, **options) - results = {} - names.each do |name| - key = normalize_key(name, options) - version = normalize_version(name, options) - entry = read_entry(key, **options) + names.each_with_object({}) do |name, results| + key = normalize_key(name, options) + entry = read_entry(key, **options) - if entry - if entry.expired? - delete_entry(key, **options) - elsif entry.mismatched?(version) - # Skip mismatched versions - else - results[name] = entry.value - end + next unless entry + + version = normalize_version(name, options) + + if entry.expired? + delete_entry(key, **options) + elsif !entry.mismatched?(version) + results[name] = entry.value end end - results end # Writes multiple entries to the cache implementation. Subclasses MAY