diff options
author | Paco Guzman <pacoguzmanp@gmail.com> | 2016-07-13 10:23:55 +0300 |
---|---|---|
committer | Paco Guzman <pacoguzmanp@gmail.com> | 2016-07-13 12:19:21 +0300 |
commit | cc752f241ccef3b13486544f03ae716de00cc363 (patch) | |
tree | 0bfcc95995cfe87d6adffdc76b93f8b94e18e982 /lib/banzai | |
parent | 5fea640e90fb8d5d50a777580d273f6d0f5fbb59 (diff) |
ObjectRenderer doesn't crash when no objects to cache with Rails.cache.read_multi
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/renderer.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/banzai/renderer.rb b/lib/banzai/renderer.rb index ea10b06439b..910687a7b6a 100644 --- a/lib/banzai/renderer.rb +++ b/lib/banzai/renderer.rb @@ -61,10 +61,16 @@ module Banzai end cacheable_items, non_cacheable_items = items_collection.partition { |item| item.key?(:cache_key) } - items_in_cache = Rails.cache.read_multi(*cacheable_items.map { |item| item[:cache_key] }) - items_not_in_cache = cacheable_items.reject do |item| - item[:rendered] = items_in_cache[item[:cache_key]] - items_in_cache.key?(item[:cache_key]) + + items_in_cache = [] + items_not_in_cache = [] + + unless cacheable_items.empty? + items_in_cache = Rails.cache.read_multi(*cacheable_items.map { |item| item[:cache_key] }) + items_not_in_cache = cacheable_items.reject do |item| + item[:rendered] = items_in_cache[item[:cache_key]] + items_in_cache.key?(item[:cache_key]) + end end (items_not_in_cache + non_cacheable_items).each do |item| |