From 4d188ca5b0a0c26d60bd196511affa5d1cf6a582 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Sat, 25 Oct 2014 02:37:57 -0700 Subject: [PATCH] Added back the `last_use` timestamp to the `AbstractAdapter` This was removed in https://github.com/rails/rails/commit/9e457a8654fa89fe329719f88ae3679aefb21e56 --- lib/freedom_patches/pool_drainer.rb | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/freedom_patches/pool_drainer.rb b/lib/freedom_patches/pool_drainer.rb index f953b32a42d..f6e2498a530 100644 --- a/lib/freedom_patches/pool_drainer.rb +++ b/lib/freedom_patches/pool_drainer.rb @@ -1,6 +1,29 @@ +if rails_master? + class ActiveRecord::ConnectionAdapters::AbstractAdapter + module LastUseExtension + attr_reader :last_use + + def initialize(connection, logger = nil, pool = nil) + super + @last_use = false + end + + def lease + synchronize do + unless in_use? + @last_use = Time.now + super + end + end + end + end + + prepend LastUseExtension + end +end + class ActiveRecord::ConnectionAdapters::ConnectionPool - # drain all idle connections # if idle_time is specified only connections idle for N seconds will be drained def drain(idle_time=nil) @@ -29,5 +52,4 @@ class ActiveRecord::ConnectionAdapters::ConnectionPool false end - end