From e0947fcbd43846714b31358a8b86ff472b16542f Mon Sep 17 00:00:00 2001 From: Navin Peiris Date: Fri, 22 May 2015 00:40:22 +0530 Subject: [PATCH] Fixing issue where fragment cache calls attribute methods multiple times, even when they are supposed to be cached --- lib/active_model/serializer/adapter/fragment_cache.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/active_model/serializer/adapter/fragment_cache.rb b/lib/active_model/serializer/adapter/fragment_cache.rb index 93d02f65..2b7596a4 100644 --- a/lib/active_model/serializer/adapter/fragment_cache.rb +++ b/lib/active_model/serializer/adapter/fragment_cache.rb @@ -35,8 +35,9 @@ module ActiveModel private def cached_attributes(klass, serializers) - cached_attributes = (klass._cache_only) ? klass._cache_only : serializer.attributes.keys.delete_if {|attr| klass._cache_except.include?(attr) } - non_cached_attributes = serializer.attributes.keys.delete_if {|attr| cached_attributes.include?(attr) } + attributes = serializer.class._attributes + cached_attributes = (klass._cache_only) ? klass._cache_only : attributes.reject {|attr| klass._cache_except.include?(attr) } + non_cached_attributes = attributes - cached_attributes cached_attributes.each do |attribute| options = serializer.class._attributes_keys[attribute] @@ -75,4 +76,4 @@ module ActiveModel end end end -end \ No newline at end of file +end