class ActiveRecord::ShardFor::AllShardsInParallel
Public Class Methods
new(shards, service:)
click to toggle source
@param [Array<Class>] An array of shard model class @param [Expeditor::Service] service
# File lib/activerecord/shard_for/all_shards_in_parallel.rb, line 8 def initialize(shards, service:) @shards = shards @service = service end
Public Instance Methods
each(&block)
click to toggle source
@yield [Class] A shard model class @return [ActiveRecord::ShardFor::AllShardsInParallel] @example
User.all_shards_in_parallel.each {|m| puts m.count }
# File lib/activerecord/shard_for/all_shards_in_parallel.rb, line 39 def each(&block) map(&block) if block_given? self end
flat_map(&block)
click to toggle source
@yield [Class] A shard model class @return [Array] A result @example
User.all_shards_in_parallel.flat_map {|m| m.where(age: 1) }
# File lib/activerecord/shard_for/all_shards_in_parallel.rb, line 31 def flat_map(&block) map(&block).flatten end
map() { |m| ... }
click to toggle source
@yield [Class] A shard model class @return [Array] A result @example
User.all_shards_in_parallel.map(&:count).reduce(&:+)
# File lib/activerecord/shard_for/all_shards_in_parallel.rb, line 17 def map return [] unless block_given? commands = @shards.map do |m| Expeditor::Command.new(service: @service) { m.connection_pool.with_connection { yield m } } end commands.each(&:start) commands.map(&:get) end