From 79b45a68199d0cdbaf5f3ed1829e6f5f78308298 Mon Sep 17 00:00:00 2001 From: Drew Caddell Date: Thu, 15 Oct 2020 12:14:20 -0700 Subject: [PATCH] TECH-4819: Apply version specific Rails patches in the appropriate adapter modules --- .../fibered_database_connection_pool.rb | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/fibered_mysql2/fibered_database_connection_pool.rb b/lib/fibered_mysql2/fibered_database_connection_pool.rb index 0611b00..ce0ec77 100644 --- a/lib/fibered_mysql2/fibered_database_connection_pool.rb +++ b/lib/fibered_mysql2/fibered_database_connection_pool.rb @@ -124,12 +124,44 @@ module Adapter_4_2 def cached_connections @reserved_connections end + + def current_connection_id + ActiveRecord::Base.connection_id ||= Fiber.current.object_id + end + + def checkout + begin + reap_connections + rescue => ex + ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}") + end + super + end end module Adapter_5_2 def cached_connections @thread_cached_conns end + + def current_connection_id + connection_cache_key(current_thread) + end + + def checkout(checkout_timeout = @checkout_timeout) + begin + reap_connections + rescue => ex + ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}") + end + super + end + + def release_connection(owner_thread = Fiber.current) + if (conn = @thread_cached_conns.delete(connection_cache_key(owner_thread))) + checkin(conn) + end + end end case Rails::VERSION::MAJOR @@ -165,36 +197,6 @@ def connection end end - if Rails::VERSION::MAJOR > 4 - def release_connection(owner_thread = Fiber.current) - if (conn = @thread_cached_conns.delete(connection_cache_key(owner_thread))) - checkin(conn) - end - end - end - - def current_connection_id - case Rails::VERSION::MAJOR - when 4 - ActiveRecord::Base.connection_id ||= Fiber.current.object_id - else - connection_cache_key(current_thread) - end - end - - def checkout(checkout_timeout = @checkout_timeout) - begin - reap_connections - rescue => ex - ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}") - end - if Rails::VERSION::MAJOR > 4 - super - else - super() - end - end - def reap_connections cached_connections.values.each do |connection| unless connection.owner.alive?