Skip to content

Commit 12adb2e

Browse files
committed
Merge pull request #924 from navinpeiris/fragment-cache
Avoid unecessary calls to attribute methods when fragment caching
2 parents 16f7512 + e0947fc commit 12adb2e

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)