Last active
January 23, 2017 21:26
-
-
Save benone/eb51e3481cf6a7d2ac2191bc20d9d664 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
module ChewyPostgresCursorAdapter | |
def import_scope(scope, options) | |
result = true | |
objects = [] | |
index = 0 | |
scope.each_instance(block_size: options[:batch_size]) do |instance| | |
objects << instance | |
if index >= options[:batch_size] | |
result &= yield grouped_objects(objects) | |
objects = [] | |
index = 0 | |
end | |
index += 1 | |
end | |
result &= yield grouped_objects(objects) | |
result | |
end | |
end | |
Chewy::Type::Adapter::ActiveRecord.prepend(ChewyPostgresCursorAdapter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment