Sha256: 987165a15305cf3e2714c2c9b39450d3d301365e34adf471860949493faf823f

Contents?: true

Size: 1006 Bytes

Versions: 9

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    class PoolManager # :nodoc:
      def initialize
        @name_to_role_mapping = Hash.new { |h, k| h[k] = {} }
      end

      def shard_names
        @name_to_role_mapping.values.flat_map { |shard_map| shard_map.keys }
      end

      def role_names
        @name_to_role_mapping.keys
      end

      def pool_configs(role = nil)
        if role
          @name_to_role_mapping[role].values
        else
          @name_to_role_mapping.flat_map { |_, shard_map| shard_map.values }
        end
      end

      def remove_role(role)
        @name_to_role_mapping.delete(role)
      end

      def remove_pool_config(role, shard)
        @name_to_role_mapping[role].delete(shard)
      end

      def get_pool_config(role, shard)
        @name_to_role_mapping[role][shard]
      end

      def set_pool_config(role, shard, pool_config)
        @name_to_role_mapping[role][shard] = pool_config
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
activerecord-6.1.3.2 lib/active_record/connection_adapters/pool_manager.rb
activerecord-6.1.3.1 lib/active_record/connection_adapters/pool_manager.rb
activerecord-6.1.3 lib/active_record/connection_adapters/pool_manager.rb
activerecord-6.1.2.1 lib/active_record/connection_adapters/pool_manager.rb
activerecord-6.1.2 lib/active_record/connection_adapters/pool_manager.rb
activerecord-6.1.1 lib/active_record/connection_adapters/pool_manager.rb
activerecord-6.1.0 lib/active_record/connection_adapters/pool_manager.rb
activerecord-6.1.0.rc2 lib/active_record/connection_adapters/pool_manager.rb
activerecord-6.1.0.rc1 lib/active_record/connection_adapters/pool_manager.rb