Sha256: 7565866420cb27101273704da4479c9ddfe1e4e0d1a5d31bdab87abdcbbe6e73

Contents?: true

Size: 931 Bytes

Versions: 1

Compression:

Stored size: 931 Bytes

Contents

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

# release ActiveRecord connections on yield
if defined?(ActiveRecord)
  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

1 entries across 1 versions & 1 rubygems

Version Path
rage-rb-1.3.0 lib/rage/ext/setup.rb