diff options
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 4475019e0e..4297c26413 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -59,7 +59,7 @@ module ActiveRecord class ConnectionPool attr_accessor :automatic_reconnect attr_reader :spec, :connections - attr_reader :columns, :columns_hash, :primary_keys + attr_reader :columns, :columns_hash, :primary_keys, :tables # Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification # object which describes database connection information (e.g. adapter, @@ -84,12 +84,7 @@ module ActiveRecord @connections = [] @checked_out = [] @automatic_reconnect = true - - @tables = Hash.new do |h, table_name| - with_connection do |conn| - h[table_name] = conn.table_exists?(table_name) - end - end + @tables = {} @columns = Hash.new do |h, table_name| h[table_name] = with_connection do |conn| @@ -113,21 +108,30 @@ module ActiveRecord @primary_keys = Hash.new do |h, table_name| h[table_name] = with_connection do |conn| - @tables[table_name] ? conn.primary_key(table_name) : 'id' + table_exists?(table_name) ? conn.primary_key(table_name) : 'id' end end end + # A cached lookup for table existence + def table_exists?(name) + return true if @tables.key? name + + with_connection do |conn| + conn.tables.each { |table| @tables[table] = true } + end + + @tables.key? name + end + # Clears out internal caches: # # * columns # * columns_hash - # * primary_keys # * tables def clear_cache! @columns.clear @columns_hash.clear - @primary_keys.clear @tables.clear end |