Remove unnecessary Serializer#cached_fields

This commit is contained in:
Benjamin Fleischer 2016-04-14 22:01:56 -05:00
parent eb86663393
commit 96750b2f9a
2 changed files with 6 additions and 11 deletions

View File

@ -206,15 +206,6 @@ module ActiveModel
end end
end end
# Get attributes from @cached_attributes
# @return [Hash] cached attributes
# def cached_attributes(fields, adapter_instance)
def cached_fields(fields, adapter_instance)
cache_check(adapter_instance) do
attributes(fields)
end
end
def cache_check(adapter_instance) def cache_check(adapter_instance)
if self.class.cache_enabled? if self.class.cache_enabled?
self.class.cache_store.fetch(cache_key(adapter_instance), self.class._cache_options) do self.class.cache_store.fetch(cache_key(adapter_instance), self.class._cache_options) do

View File

@ -37,10 +37,14 @@ module ActiveModelSerializers
cached_attributes = instance_options[:cached_attributes] || {} cached_attributes = instance_options[:cached_attributes] || {}
key = serializer.cache_key(self) key = serializer.cache_key(self)
cached_attributes.fetch(key) do cached_attributes.fetch(key) do
serializer.cached_fields(options[:fields], self) serializer.cache_check(self) do
serializer.attributes(options[:fields])
end
end end
else else
serializer.cached_fields(options[:fields], self) serializer.cache_check(self) do
serializer.attributes(options[:fields])
end
end end
relationships = resource_relationships(options) relationships = resource_relationships(options)
resource.merge(relationships) resource.merge(relationships)