Sha256: a45edae41a0dc91c1b66a3f00958e12152e8c714f9fa16401118accf8ada8dda

Contents?: true

Size: 1.54 KB

Versions: 41

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    class PoolConfig # :nodoc:
      include Mutex_m

      attr_reader :db_config, :connection_class, :role, :shard
      attr_accessor :schema_cache

      INSTANCES = ObjectSpace::WeakMap.new
      private_constant :INSTANCES

      class << self
        def discard_pools!
          INSTANCES.each_key(&:discard_pool!)
        end
      end

      def initialize(connection_class, db_config, role, shard)
        super()
        @connection_class = connection_class
        @db_config = db_config
        @role = role
        @shard = shard
        @pool = nil
        INSTANCES[self] = self
      end

      def connection_specification_name
        if connection_class.primary_class?
          "ActiveRecord::Base"
        else
          connection_class.name
        end
      end

      def disconnect!
        ActiveSupport::ForkTracker.check!

        return unless @pool

        synchronize do
          return unless @pool

          @pool.automatic_reconnect = false
          @pool.disconnect!
        end

        nil
      end

      def pool
        ActiveSupport::ForkTracker.check!

        @pool || synchronize { @pool ||= ConnectionAdapters::ConnectionPool.new(self) }
      end

      def discard_pool!
        return unless @pool

        synchronize do
          return unless @pool

          @pool.discard!
          @pool = nil
        end
      end
    end
  end
end

ActiveSupport::ForkTracker.after_fork { ActiveRecord::ConnectionAdapters::PoolConfig.discard_pools! }

Version data entries

41 entries across 39 versions & 6 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.8.7/lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.8.7 lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.8.6 lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.8.5 lib/active_record/connection_adapters/pool_config.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/active_record/connection_adapters/pool_config.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/pool_config.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/pool_config.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.8.4 lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.8.1 lib/active_record/connection_adapters/pool_config.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.2.3/lib/active_record/connection_adapters/pool_config.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.8 lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.7.2 lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.7.1 lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.7 lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.6 lib/active_record/connection_adapters/pool_config.rb
activerecord-7.0.5.1 lib/active_record/connection_adapters/pool_config.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/pool_config.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activerecord-7.0.2.3/lib/active_record/connection_adapters/pool_config.rb