aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-08-31 11:53:50 +0100
committerJon Leighton <j@jonathanleighton.com>2012-08-31 15:56:27 +0100
commit221571beb6b4bb7437989bdefaf421f993ab6002 (patch)
treec546a8b970c4ec8927dfbd287f36eec83d08477e /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
parentae79c7a201f3aeea8919790eca1faa3fb552f88a (diff)
downloadrails-221571beb6b4bb7437989bdefaf421f993ab6002.tar.gz
rails-221571beb6b4bb7437989bdefaf421f993ab6002.tar.bz2
rails-221571beb6b4bb7437989bdefaf421f993ab6002.zip
Make connection pool retrieval faster
* Loop rather than recurse in retrieve_connection_pool * Key the hash by class rather than class name. This avoids creating unnecessary strings.
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.rb23
1 files changed, 13 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 347d794fa3..1f731036c9 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -505,9 +505,9 @@ module ActiveRecord
@connection_pools[Process.pid]
end
- def establish_connection(name, spec)
+ def establish_connection(klass, spec)
set_pool_for_spec spec, ConnectionAdapters::ConnectionPool.new(spec)
- set_class_to_pool name, connection_pools[spec]
+ set_class_to_pool klass, connection_pools[spec]
end
# Returns true if there are any active connections among the connection
@@ -553,7 +553,7 @@ module ActiveRecord
# can be used as an argument for establish_connection, for easily
# re-establishing the connection.
def remove_connection(klass)
- pool = class_to_pool.delete(klass.name)
+ pool = class_to_pool.delete(klass)
return nil unless pool
connection_pools.delete pool.spec
@@ -563,12 +563,15 @@ module ActiveRecord
end
def retrieve_connection_pool(klass)
- if !(klass < Model::Tag)
- get_pool_for_class('ActiveRecord::Model') # default connection
- else
- pool = get_pool_for_class(klass.name)
- pool || retrieve_connection_pool(klass.superclass)
+ pool = get_pool_for_class(klass)
+
+ until pool
+ klass = klass.superclass
+ break unless klass < Model::Tag
+ pool = get_pool_for_class(klass)
end
+
+ pool || get_pool_for_class(ActiveRecord::Model)
end
private
@@ -581,8 +584,8 @@ module ActiveRecord
@connection_pools[Process.pid][spec] = pool
end
- def set_class_to_pool(name, pool)
- @class_to_pool[Process.pid][name] = pool
+ def set_class_to_pool(klass, pool)
+ @class_to_pool[Process.pid][klass] = pool
pool
end