Sha256: 4f32c2ca2e25cbdb5f1f122161857eef4216945b147bff3bafd213fc36236f8a

Contents?: true

Size: 728 Bytes

Versions: 23

Compression:

Stored size: 728 Bytes

Contents

module ActiveRecord::Turntable
  class Mixer
    class Fader
      class CalculateShardsSumResult < Fader
        def execute
          results = @shards_query_hash.map do |shard, query|
            args = @args.dup
            args[1] = args[1].dup if args[1].present?
            shard.connection.send(@called_method, query, *@args, &@block)
          end
          merge_results(results)
        end

        private

        def merge_results(results)
          ActiveRecord::Result.new(
            results.first.columns,
            results[0].rows.zip(*results[1..-1].map{|r| r.rows}).map {|r| [r.map {|v| v.first}.inject(&:+)]},
            results.first.column_types
          )
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
activerecord-turntable-2.0.1 lib/active_record/turntable/mixer/fader/calculate_shards_sum_result.rb
activerecord-turntable-2.0.0 lib/active_record/turntable/mixer/fader/calculate_shards_sum_result.rb
activerecord-turntable-2.0.0.rc1 lib/active_record/turntable/mixer/fader/calculate_shards_sum_result.rb