Sha256: c1aa14be809516a5a361523fd8071fc678db062edfcc5de9d970fceabc35d3d9

Contents?: true

Size: 731 Bytes

Versions: 23

Compression:

Stored size: 731 Bytes

Contents

module CassandraObject
  class Scope
    module Batches
      def find_each(options = {})
        find_in_batches(options) do |records|
          records.each { |record| yield record }
        end
      end

      def find_in_batches(options = {})
        batch_size = options.delete(:batch_size) || 1000
        start_key = nil

        scope = limit(batch_size + 1)
        records = scope.to_a

        while records.any?
          if records.size > batch_size
            next_record = records.pop
          else
             next_record = nil
          end

          yield records
          break if next_record.nil?

          records = scope.where("KEY >= '#{next_record.id}'").to_a
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
gotime-cassandra_object-4.11.5 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.11.4 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.11.3 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.11.2 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.11.1 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.11.0 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.10.5 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.10.4 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.10.3 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.10.2 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.10.1 lib/cassandra_object/scope/batches.rb
cassandra_object_rails-0.0.1 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.10.0 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.9.2 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.9.1 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.9.0 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.8.1 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.8.0 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.7.3 lib/cassandra_object/scope/batches.rb
gotime-cassandra_object-4.7.2 lib/cassandra_object/scope/batches.rb