File tree Expand file tree Collapse file tree 2 files changed +20
-14
lines changed
active_model_serializers/adapter Expand file tree Collapse file tree 2 files changed +20
-14
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,6 +208,21 @@ def object_cache_key(serializer, adapter_instance)
206
208
end
207
209
end
208
210
211
+ def cached_attributes ( options , 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 ( options [ :fields ] )
217
+ end
218
+ end
219
+ else
220
+ cache_check ( adapter_instance ) do
221
+ attributes ( options [ :fields ] )
222
+ end
223
+ end
224
+ end
225
+
209
226
def cache_check ( adapter_instance )
210
227
if self . class . cache_enabled?
211
228
self . class . cache_store . fetch ( cache_key ( adapter_instance ) , self . class . _cache_options ) do
@@ -322,3 +339,4 @@ def object_cache_key
322
339
end
323
340
end
324
341
end
342
+ # rubocop:enable Metrics/ModuleLength
Original file line number Diff line number Diff line change @@ -32,20 +32,8 @@ def serializable_hash_for_collection(options)
32
32
end
33
33
34
34
def serializable_hash_for_single_resource ( options )
35
- resource =
36
- if serializer . class . cache_enabled?
37
- cached_attributes = instance_options [ :cached_attributes ] || { }
38
- key = serializer . cache_key ( self )
39
- cached_attributes . fetch ( key ) do
40
- serializer . cache_check ( self ) do
41
- serializer . attributes ( options [ :fields ] )
42
- end
43
- end
44
- else
45
- serializer . cache_check ( self ) do
46
- serializer . attributes ( options [ :fields ] )
47
- end
48
- end
35
+ cached_attributes = instance_options [ :cached_attributes ] || { }
36
+ resource = serializer . cached_attributes ( options , cached_attributes , self )
49
37
relationships = resource_relationships ( options )
50
38
resource . merge ( relationships )
51
39
end
You can’t perform that action at this time.
0 commit comments