Skip to content

Instantly share code, notes, and snippets.

@benone
Last active January 23, 2017 21:26
Show Gist options
  • Save benone/eb51e3481cf6a7d2ac2191bc20d9d664 to your computer and use it in GitHub Desktop.
Save benone/eb51e3481cf6a7d2ac2191bc20d9d664 to your computer and use it in GitHub Desktop.
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