module Journey::Resource::BatchWhere

Public Class Methods

batch_where(clauses, batch_size=100) click to toggle source
# File lib/journey/resource/batch_where.rb, line 8
def self.batch_where(clauses, batch_size=100)
  total_count = count_multiple(clauses)
  query_count = (total_count / batch_size.to_f).ceil.to_i

  (0 ... query_count).to_a.map do |batch_index|

    where_multiple clauses.merge({
      limit: batch_size,
      skip: batch_index * batch_size
    })

  end.flatten
end