aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-07 09:25:57 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-07 09:26:52 -0800
commit0de661d6c74172a9fedcced6a4e99d007df953ef (patch)
tree3644bd0f1acab9e6972c66f371ee309e30e841df /activerecord/lib
parent285fdbae2bafd5de415a685b57af36254197348c (diff)
downloadrails-0de661d6c74172a9fedcced6a4e99d007df953ef.tar.gz
rails-0de661d6c74172a9fedcced6a4e99d007df953ef.tar.bz2
rails-0de661d6c74172a9fedcced6a4e99d007df953ef.zip
the connection pool caches table_exists? calls
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb22
1 files changed, 14 insertions, 8 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..b1754e61df 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,11 +108,22 @@ 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