mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Backport caching of the constant lookup
This commit is contained in:
@@ -4,13 +4,15 @@ module ActiveModel
|
||||
extend self
|
||||
|
||||
def _const_get(const)
|
||||
begin
|
||||
method = RUBY_VERSION >= '2.0' ? :const_get : :qualified_const_get
|
||||
Object.send method, const
|
||||
rescue NameError
|
||||
const.safe_constantize
|
||||
Serializer.serializers_cache.fetch_or_store(const) do
|
||||
begin
|
||||
method = RUBY_VERSION >= '2.0' ? :const_get : :qualified_const_get
|
||||
Object.send method, const
|
||||
rescue NameError
|
||||
const.safe_constantize
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ require 'active_model/serializer/association'
|
||||
require 'active_model/serializer/config'
|
||||
|
||||
require 'thread'
|
||||
require 'concurrent/map'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
@@ -100,6 +101,10 @@ end
|
||||
associate(Association::HasMany, *attrs)
|
||||
end
|
||||
|
||||
def serializers_cache
|
||||
@serializers_cache ||= Concurrent::Map.new
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def strip_attribute(attr)
|
||||
|
||||
Reference in New Issue
Block a user