Skip to content

Commit

Permalink
TECH-4819: Apply version specific Rails patches in the appropriate ad…
Browse files Browse the repository at this point in the history
…apter modules
  • Loading branch information
dcaddell committed Oct 15, 2020
1 parent 9326376 commit 79b45a6
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions lib/fibered_mysql2/fibered_database_connection_pool.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 79b45a6

Please sign in to comment.