diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-08-31 11:53:50 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-08-31 15:56:27 +0100 |
commit | 221571beb6b4bb7437989bdefaf421f993ab6002 (patch) | |
tree | c546a8b970c4ec8927dfbd287f36eec83d08477e /activerecord/lib | |
parent | ae79c7a201f3aeea8919790eca1faa3fb552f88a (diff) | |
download | rails-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')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 23 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_handling.rb | 2 |
2 files changed, 14 insertions, 11 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 diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb index 7863c795ed..3531be05bf 100644 --- a/activerecord/lib/active_record/connection_handling.rb +++ b/activerecord/lib/active_record/connection_handling.rb @@ -44,7 +44,7 @@ module ActiveRecord end remove_connection - connection_handler.establish_connection name, spec + connection_handler.establish_connection self, spec end # Returns the connection currently associated with the class. This can |