<commit_before>
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)
    synchronize do
      @available.clear
      @connections.delete_if do |conn|
        try_drain?(conn, idle_time)
      end

      @connections.each do |conn|
        @available.add conn if !conn.in_use?
      end
    end

  end

  private

  def try_drain?(conn, idle_time)
    if !conn.in_use?
      if !idle_time || conn.last_use < idle_time.seconds.ago
        conn.disconnect!
        return true
      end
    end

    false
  end

end
<commit_msg>Added back the `last_use` timestamp to the `AbstractAdapter`<commit_after>
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)
    synchronize do
      @available.clear
      @connections.delete_if do |conn|
        try_drain?(conn, idle_time)
      end

      @connections.each do |conn|
        @available.add conn if !conn.in_use?
      end
    end

  end

  private

  def try_drain?(conn, idle_time)
    if !conn.in_use?
      if !idle_time || conn.last_use < idle_time.seconds.ago
        conn.disconnect!
        return true
      end
    end

    false
  end
end

{'fraction_non_alphanumeric': 0.06356164383561644, 'fraction_numerical': 0.0, 'mean_word_length': 2.332116788321168, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2537793', 'n_tokens_mistral': 560, 'n_tokens_neox': 546, 'n_words': 160}