Sha256: bab07ba3727b9e9e6591c08bd8930dbe71a2232ad9798c752236a114e76593aa

Contents?: true

Size: 986 Bytes

Versions: 4

Compression:

Stored size: 986 Bytes

Contents

# set ActiveSupport isolation level
if defined?(ActiveSupport::IsolatedExecutionState)
  ActiveSupport::IsolatedExecutionState.isolation_level = :fiber
end

# release ActiveRecord connections on yield
if defined?(ActiveRecord) && ActiveRecord.version < Gem::Version.create("7.1.0")
  class Fiber
    def self.defer
      res = Fiber.yield

      if ActiveRecord::Base.connection_pool.active_connection?
        ActiveRecord::Base.connection_handler.clear_active_connections!
      end

      res
    end
  end
end

# make `ActiveRecord::ConnectionPool` work correctly with fibers
if defined?(ActiveRecord::ConnectionAdapters::ConnectionPool)
  ActiveRecord::ConnectionAdapters::ConnectionPool
  module ActiveRecord::ConnectionAdapters
    class ConnectionPool
      def connection_cache_key(_)
        Fiber.current
      end
    end
  end
end

# patch `ActiveRecord::ConnectionPool`
if defined?(ActiveRecord) && ENV["RAGE_PATCH_AR_POOL"]
  Rage.patch_active_record_connection_pool
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rage-rb-1.8.0 lib/rage/ext/setup.rb
rage-rb-1.7.0 lib/rage/ext/setup.rb
rage-rb-1.6.0 lib/rage/ext/setup.rb
rage-rb-1.4.0 lib/rage/ext/setup.rb