Created
October 8, 2011 12:18
-
-
Save justinko/1272234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_in_batches(model) | |
current_batch, count = 0, model.count | |
while count > 0 do | |
model.all.skip(current_batch * 1000).limit(1000).each do |doc| | |
yield doc | |
end | |
count -= 1000 | |
current_batch += 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment