提交 b03f9ef8 编写于 作者: S Sean Griffin

Revert "PERF: optimise type lookup to avoid invoking procs"

This reverts commit da99a2a2.
上级 74c35b46
...@@ -431,22 +431,16 @@ def translate_exception(exception, message) ...@@ -431,22 +431,16 @@ def translate_exception(exception, message)
private private
def get_oid_type(oid, fmod, column_name, sql_type = '') # :nodoc: def get_oid_type(oid, fmod, column_name, sql_type = '') # :nodoc:
if !type_map.key?(oid)
result = type_map.fetch(oid, fmod, sql_type) {
nil
}
unless result
load_additional_types(type_map, [oid]) load_additional_types(type_map, [oid])
result = type_map.fetch(oid, fmod, sql_type) {
warn "unknown OID #{oid}: failed to recognize type of '#{column_name}'. It will be treated as String."
Type::Value.new.tap do |cast_type|
type_map.register_type(oid, cast_type)
end
}
end end
result type_map.fetch(oid, fmod, sql_type) {
warn "unknown OID #{oid}: failed to recognize type of '#{column_name}'. It will be treated as String."
Type::Value.new.tap do |cast_type|
type_map.register_type(oid, cast_type)
end
}
end end
def initialize_type_map(m) # :nodoc: def initialize_type_map(m) # :nodoc:
......
module ActiveRecord module ActiveRecord
module Type module Type
class HashLookupTypeMap < TypeMap # :nodoc: class HashLookupTypeMap < TypeMap # :nodoc:
def initialize
@cache = {}
super
end
delegate :key?, to: :@mapping delegate :key?, to: :@mapping
def lookup(type, *args) def lookup(type, *args)
...@@ -14,24 +8,12 @@ def lookup(type, *args) ...@@ -14,24 +8,12 @@ def lookup(type, *args)
end end
def fetch(type, *args, &block) def fetch(type, *args, &block)
cache = (@cache[type] ||= {}) @mapping.fetch(type, block).call(type, *args)
resolved = cache[args]
unless resolved
resolved = cache[args] = @mapping.fetch(type, block).call(type, *args)
end
resolved
end end
def alias_type(type, alias_type) def alias_type(type, alias_type)
register_type(type) { |_, *args| lookup(alias_type, *args) } register_type(type) { |_, *args| lookup(alias_type, *args) }
end end
def register_type(key, value=nil, &block)
@cache = {}
super(key, value, &block)
end
end end
end end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册