aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-12-30 13:47:10 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-12-30 13:47:10 -0800
commit5dc7257b7a170c3c4719ccdb084ad3b4c1d227a1 (patch)
tree0557f88c79d15922b31bc9c1d1a08309ab68a854 /activerecord
parentdf9de6fc6c2e950303088500cb4f4660d89a71b6 (diff)
downloadrails-5dc7257b7a170c3c4719ccdb084ad3b4c1d227a1.tar.gz
rails-5dc7257b7a170c3c4719ccdb084ad3b4c1d227a1.tar.bz2
rails-5dc7257b7a170c3c4719ccdb084ad3b4c1d227a1.zip
refactor checking out the connection
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb11
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 ee2e419a56..b548412644 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -186,13 +186,14 @@ module ActiveRecord
def checkout
# Checkout an available connection
synchronize do
+ # Try to find a connection that hasn't been leased
conn = @connections.find { |c| c.lease }
- unless conn
- if @connections.size < @size
- conn = checkout_new_connection
- conn.lease
- end
+ # If all connections were leased, and we have room to expand,
+ # create a new connection and lease it.
+ if !conn && @connections.size < @size
+ conn = checkout_new_connection
+ conn.lease
end
if conn