diff options
author | steve <coderrr.contact@gmail.com> | 2009-05-01 14:58:10 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-05-01 14:58:10 +0100 |
commit | 5501b99a19a2a67a9a920fd3c7bff071a2ecf058 (patch) | |
tree | 801cbec74d31e7600c172a5146a30a3953f61cc0 /activerecord/lib/active_record/connection_adapters/abstract | |
parent | b193f233908823cccd2f1d5fcb4146787ed8c4ed (diff) | |
download | rails-5501b99a19a2a67a9a920fd3c7bff071a2ecf058.tar.gz rails-5501b99a19a2a67a9a920fd3c7bff071a2ecf058.tar.bz2 rails-5501b99a19a2a67a9a920fd3c7bff071a2ecf058.zip |
Ensure ActiveRecord::Base.connection_pool.with_connection creates a new connection only when needed [#1752 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 11 |
1 files changed, 6 insertions, 5 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 aac84cc5f4..e8e736bf38 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -107,13 +107,14 @@ module ActiveRecord checkin conn if conn end - # Reserve a connection, and yield it to a block. Ensure the connection is - # checked back in when finished. + # If a connection already exists yield it to the block. If no connection + # exists checkout a connection, yield it to the block, and checkin the + # connection when finished. def with_connection - conn = checkout - yield conn + fresh_connection = true unless @reserved_connections[current_connection_id] + yield connection ensure - checkin conn + release_connection if fresh_connection end # Returns true if a connection has already been opened. |