diff options
author | Sam <sam.saffron@gmail.com> | 2014-11-17 14:55:17 +1100 |
---|---|---|
committer | Sam <sam.saffron@gmail.com> | 2014-11-17 14:55:17 +1100 |
commit | da99a2a2982d35f670ad9647463e09bfe9032b70 (patch) | |
tree | e4c452a2fe9d542e2b8e15b41d312f2a0d44531b /activerecord/lib/active_record/connection_adapters | |
parent | 3a804aab9557efd1f1f3b68a5d1e9e3c2f37df20 (diff) | |
download | rails-da99a2a2982d35f670ad9647463e09bfe9032b70.tar.gz rails-da99a2a2982d35f670ad9647463e09bfe9032b70.tar.bz2 rails-da99a2a2982d35f670ad9647463e09bfe9032b70.zip |
PERF: optimise type lookup to avoid invoking procs
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 6310d70192..d3e5b0a4ad 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -431,16 +431,22 @@ module ActiveRecord private 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]) + 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 - 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 - } + result end def initialize_type_map(m) # :nodoc: |