File tree Expand file tree Collapse file tree 2 files changed +17
-19
lines changed
active_model_serializers/adapter Expand file tree Collapse file tree 2 files changed +17
-19
lines changed Original file line number Diff line number Diff line change
1
+ # TODO(BF): refactor file to be smaller
2
+ # rubocop:disable Metrics/ModuleLength
1
3
module ActiveModel
2
4
class Serializer
3
5
UndefinedCacheKey = Class . new ( StandardError )
@@ -206,12 +208,18 @@ def object_cache_key(serializer, adapter_instance)
206
208
end
207
209
end
208
210
209
- # Get attributes from @cached_attributes
210
- # @return [Hash] cached attributes
211
- # def cached_attributes(fields, adapter_instance)
212
- def cached_fields ( fields , adapter_instance )
213
- cache_check ( adapter_instance ) do
214
- attributes ( fields )
211
+ def cached_attributes ( fields , cached_attributes , adapter_instance )
212
+ if self . class . cache_enabled?
213
+ key = cache_key ( adapter_instance )
214
+ cached_attributes . fetch ( key ) do
215
+ cache_check ( adapter_instance ) do
216
+ attributes ( fields )
217
+ end
218
+ end
219
+ else
220
+ cache_check ( adapter_instance ) do
221
+ attributes ( fields )
222
+ end
215
223
end
216
224
end
217
225
@@ -331,3 +339,4 @@ def object_cache_key
331
339
end
332
340
end
333
341
end
342
+ # rubocop:enable Metrics/ModuleLength
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ def serializable_hash_for_collection(options)
32
32
end
33
33
34
34
def serializable_hash_for_single_resource ( options )
35
- resource = resource_object_for ( options )
35
+ cached_attributes = instance_options [ :cached_attributes ] || { }
36
+ resource = serializer . cached_attributes ( options [ :fields ] , cached_attributes , self )
36
37
relationships = resource_relationships ( options )
37
38
resource . merge ( relationships )
38
39
end
@@ -60,18 +61,6 @@ def relationship_value_for(association, options)
60
61
61
62
relationship_value
62
63
end
63
-
64
- def resource_object_for ( options )
65
- if serializer . class . cache_enabled?
66
- cached_attributes = instance_options [ :cached_attributes ] || { }
67
- key = serializer . cache_key ( self )
68
- cached_attributes . fetch ( key ) do
69
- serializer . cached_fields ( options [ :fields ] , self )
70
- end
71
- else
72
- serializer . cached_fields ( options [ :fields ] , self )
73
- end
74
- end
75
64
end
76
65
end
77
66
end
You can’t perform that action at this time.
0 commit comments