diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-12-13 13:08:49 -0500 |
---|---|---|
committer | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-12-27 01:39:43 -0600 |
commit | 94ecf95674f81c5590c8f08549208907b81e3bf8 (patch) | |
tree | 07da284fc15dc25fa893737a6161e579bce65f68 /activesupport/lib/active_support/cache.rb | |
parent | 3a3a3d607eb2f706c117926015d2cb6ef6599ded (diff) | |
download | rails-94ecf95674f81c5590c8f08549208907b81e3bf8.tar.gz rails-94ecf95674f81c5590c8f08549208907b81e3bf8.tar.bz2 rails-94ecf95674f81c5590c8f08549208907b81e3bf8.zip |
Preserve key order passed to ActiveSupport::CacheStore#fetch_multi
fetch_multi(*names) now returns its results in the same order
as the `*names` requested, rather than returning cache hits
followed by cache misses.
Diffstat (limited to 'activesupport/lib/active_support/cache.rb')
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index e8518645d9..30a69c550b 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -438,18 +438,18 @@ module ActiveSupport options = merged_options(options) instrument :read_multi, names, options do |payload| - read_multi_entries(names, options).tap do |results| - payload[:hits] = results.keys - payload[:super_operation] = :fetch_multi + reads = read_multi_entries(names, options) + writes = {} + ordered = names.each_with_object({}) do |name, hash| + hash[name] = reads.fetch(name) { writes[name] = yield(name) } + end - writes = {} + payload[:hits] = reads.keys + payload[:super_operation] = :fetch_multi - (names - results.keys).each do |name| - results[name] = writes[name] = yield(name) - end + write_multi(writes, options) - write_multi writes, options - end + ordered end end |