Skip to content

Commit e0947fc

Browse files
committed
Fixing issue where fragment cache calls attribute methods multiple times, even when they are supposed to be cached
1 parent 5f05944 commit e0947fc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/active_model/serializer/adapter/fragment_cache.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ def fetch
3535
private
3636

3737
def cached_attributes(klass, serializers)
38-
cached_attributes = (klass._cache_only) ? klass._cache_only : serializer.attributes.keys.delete_if {|attr| klass._cache_except.include?(attr) }
39-
non_cached_attributes = serializer.attributes.keys.delete_if {|attr| cached_attributes.include?(attr) }
38+
attributes = serializer.class._attributes
39+
cached_attributes = (klass._cache_only) ? klass._cache_only : attributes.reject {|attr| klass._cache_except.include?(attr) }
40+
non_cached_attributes = attributes - cached_attributes
4041

4142
cached_attributes.each do |attribute|
4243
options = serializer.class._attributes_keys[attribute]
@@ -75,4 +76,4 @@ def fragment_serializer(name, klass)
7576
end
7677
end
7778
end
78-
end
79+
end

0 commit comments

Comments
 (0)