From 9a74b456b5470affcb3577c7b42de4d32849bf70 Mon Sep 17 00:00:00 2001 From: Andrew Rove Date: Fri, 17 Nov 2017 10:21:05 -0600 Subject: [PATCH 1/2] Multi fetch needs the array of keys splatted. --- lib/jsonapi/renderer/cached_resources_processor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jsonapi/renderer/cached_resources_processor.rb b/lib/jsonapi/renderer/cached_resources_processor.rb index 080ee99..de42cb9 100644 --- a/lib/jsonapi/renderer/cached_resources_processor.rb +++ b/lib/jsonapi/renderer/cached_resources_processor.rb @@ -17,7 +17,7 @@ def initialize(cache) def process_resources [@primary, @included].each do |resources| cache_hash = cache_key_map(resources) - processed_resources = @cache.fetch_multi(cache_hash.keys) do |key| + processed_resources = @cache.fetch_multi(*cache_hash.keys) do |key| res, include, fields = cache_hash[key] json = res.as_jsonapi(include: include, fields: fields).to_json From 979cff6f21f23d8b3cb1a1d63218948c3d4251b5 Mon Sep 17 00:00:00 2001 From: Andrew Rove Date: Fri, 17 Nov 2017 10:33:26 -0600 Subject: [PATCH 2/2] Fix tests to match rails multi_cache --- spec/caching_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/caching_spec.rb b/spec/caching_spec.rb index f153ba7..35c605c 100644 --- a/spec/caching_spec.rb +++ b/spec/caching_spec.rb @@ -5,7 +5,7 @@ def initialize @cache = {} end - def fetch_multi(keys) + def fetch_multi(*keys) keys.each_with_object({}) do |k, h| @cache[k] = yield(k) unless @cache.key?(k) h[k] = @cache[k]