Sha256: 3094466a1cbdad06d4668735cdf859b662a498794a374d8ce210e2b485d9e188

Contents?: true

Size: 917 Bytes

Versions: 23

Compression:

Stored size: 917 Bytes

Contents

module ActiveRecord::Turntable
  class Mixer
    class Fader
      class SelectShardsMergeResult < 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)
          if results.any? {|r| r.is_a?(ActiveRecord::Result) }
            first_result = results.find {|r| r.present? }
            return results.first unless first_result

            ActiveRecord::Result.new(
              first_result.columns,
              results.map {|r| r.rows}.flatten(1),
              first_result.column_types
            )
          else
            results.compact.inject(&:+)
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
activerecord-turntable-2.5.0 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.4.0 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.3.3 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.3.2 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.3.1 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.3.0 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.2.2 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.2.1 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.2.0 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.1.1 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.1.0 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.1.0.rc2 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.1.0.rc1 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.1.0.beta2 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.1.0.beta1 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.0.6 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.0.5 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.0.4 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.0.3 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
activerecord-turntable-2.0.2 lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb