module Judoscale
  class JobMetricsCollector
    module ActiveRecordHelper
      private

      def default_timezone
        if ::ActiveRecord.respond_to?(:default_timezone)
          # Rails >= 7
          ::ActiveRecord.default_timezone
        else
          # Rails < 7
          ::ActiveRecord::Base.default_timezone
        end
      end

      def select_rows_silently(sql)
        if Config.instance.log_level && ::ActiveRecord::Base.logger.respond_to?(:silence)
          ::ActiveRecord::Base.logger.silence(Config.instance.log_level) { select_rows(sql) }
        else
          select_rows(sql)
        end
      end

      def select_rows(sql)
        # This ensures the agent doesn't hold onto a DB connection any longer than necessary
        ActiveRecord::Base.connection_pool.with_connection { |c| c.select_rows(sql) }
      end
    end
  end
end

module Judoscale
  class JobMetricsCollector
    module ActiveRecordHelper
      private

      def select_rows_silently(sql)
        if Config.instance.log_level && ::ActiveRecord::Base.logger.respond_to?(:silence)
          ::ActiveRecord::Base.logger.silence(Config.instance.log_level) { select_rows(sql) }
        else
          select_rows(sql)
        end
      end

      def select_rows(sql)
        # This ensures the agent doesn't hold onto a DB connection any longer than necessary
        ActiveRecord::Base.connection_pool.with_connection { |c| c.select_rows(sql) }
      end
    end
  end
end

Remove unused default timezone method from AR helpers
Remove unused default timezone method from AR helpers

We decided to no longer log this with the AR based job adapters, so we
can remove the method safely as it's not used anywhere.

Reference: https://github.com/judoscale/judoscale-ruby/pull/64#discussion_r837548643
