diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-16 14:48:50 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-16 14:48:50 -0700 |
commit | 42be67e8d4470b0bdc6ba62fceaa6cdb1c21a097 (patch) | |
tree | 0b9dece25d17045a7fc5f4ec34da4019326485b9 /activerecord/lib/active_record | |
parent | 8d17f533187a791b4a42f45542c56c5f965e6fad (diff) | |
download | rails-42be67e8d4470b0bdc6ba62fceaa6cdb1c21a097.tar.gz rails-42be67e8d4470b0bdc6ba62fceaa6cdb1c21a097.tar.bz2 rails-42be67e8d4470b0bdc6ba62fceaa6cdb1c21a097.zip |
unfactoring clear_stale_cached_connections!
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 23 |
1 files changed, 7 insertions, 16 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 1b4ee0368e..9d0251dda3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -161,8 +161,13 @@ module ActiveRecord # Return any checked-out connections back to the pool by threads that # are no longer alive. def clear_stale_cached_connections! - remove_stale_cached_threads!(@reserved_connections) do |name, conn| - checkin conn + keys = @reserved_connections.keys - Thread.list.find_all { |t| + t.alive? + }.map { |thread| thread.object_id } + + keys.each do |key| + checkin @reserved_connections[key] + @reserved_connections.delete(key) end end @@ -232,20 +237,6 @@ module ActiveRecord Thread.current.object_id end - # Remove stale threads from the cache. - def remove_stale_cached_threads!(cache, &block) - keys = Set.new(cache.keys) - - Thread.list.each do |thread| - keys.delete(thread.object_id) if thread.alive? - end - keys.each do |key| - next unless cache.has_key?(key) - block.call(key, cache[key]) - cache.delete(key) - end - end - def checkout_new_connection c = new_connection @connections << c |