-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
If you define a serializer with a fragment cache, such as
class TestSerializer < ActiveModel::Serializer
cache key: "test", except: [:field1]
attributes :field1, :field2
endand then render in your controller, an array:
render json: resources, each_serializer: TestSerializerthe fragment cache's call to attribute (line 52) will continually add field1, such that if resources has 20 objects, by the end, field1 will be called 20 times for the last invocation of the TestSerializer.
I believe ActiveModel::Serializer.attribute should only concat the key onto @_attributes if it is not already present.
i.e., line 45 (in master) should be:
@_attributes.concat [key] unless @_attributes.include? keyAlso, since the @_attributes variable is at the class level, subsequent requests compound the issue even further.