Skip to content

Instantly share code, notes, and snippets.

@zapnap
Created February 11, 2014 21:59
Show Gist options
  • Save zapnap/8945077 to your computer and use it in GitHub Desktop.
Save zapnap/8945077 to your computer and use it in GitHub Desktop.
More efficient find_in_batches for Algolia + Mongoid
module AlgoliaMongoidBatchFind
# more efficient than the built-in adapter for bulk reindexing (mongoid adapter)
def algolia_find_in_batches(options={}, &block)
options[:batch_size] ||= 100
offset = 0
offset.step(Product.count, options[:batch_size]) do |offset|
yield Product.limit(options[:batch_size]).skip(offset).to_a
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment