File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,15 @@ module Utils
4
4
extend self
5
5
6
6
def _const_get ( const )
7
- begin
8
- method = RUBY_VERSION >= '2.0' ? :const_get : :qualified_const_get
9
- Object . send method , const
10
- rescue NameError
11
- const . safe_constantize
7
+ Serializer . serializers_cache . fetch_or_store ( const ) do
8
+ begin
9
+ method = RUBY_VERSION >= '2.0' ? :const_get : :qualified_const_get
10
+ Object . send method , const
11
+ rescue NameError
12
+ const . safe_constantize
13
+ end
12
14
end
13
15
end
14
16
end
15
17
end
16
- end
18
+ end
Original file line number Diff line number Diff line change 4
4
require 'active_model/serializer/config'
5
5
6
6
require 'thread'
7
+ require 'concurrent/map'
7
8
8
9
module ActiveModel
9
10
class Serializer
@@ -100,6 +101,10 @@ def has_many(*attrs)
100
101
associate ( Association ::HasMany , *attrs )
101
102
end
102
103
104
+ def serializers_cache
105
+ @serializers_cache ||= Concurrent ::Map . new
106
+ end
107
+
103
108
private
104
109
105
110
def strip_attribute ( attr )
Original file line number Diff line number Diff line change 14
14
ActionController ::Base . send ( :include , ::ActionController ::Serialization )
15
15
ActionController ::TestCase . send ( :include , ::ActionController ::SerializationAssertions )
16
16
end
17
+ ActionDispatch ::Reloader . to_prepare do
18
+ ActiveModel ::Serializer . serializers_cache . clear
19
+ end
17
20
end
18
21
rescue LoadError
19
22
# rails not installed, continuing
You can’t perform that action at this time.
0 commit comments