lib/inventory_refresh/application_record_iterator.rb
def find_in_batches(batch_size: 1000, attributes_index: {})
      attributes_index.each_slice(batch_size) do |batch|
        yield(inventory_collection.db_collection_for_comparison_for(batch))
      end
    end
def find_in_batches(batch_size: 1000, attributes_index: {})
      attributes_index.each_slice(batch_size) do |batch|
        yield(inventory_collection.db_collection_for_comparison_for(batch))
      end
    end
An iterator that can fetch batches of the AR objects based on a set of attribute_indexes

 @param inventory_collection [InventoryRefresh::InventoryCollection] Inventory collection owning the iterator
 Iterator that mimics find_in_batches of ActiveRecord::Relation. This iterator serves for making more optimized query
 since e.g. having 1500 ids if objects we want to return. Doing relation.where(:id => 1500ids).find_each would
 always search for all 1500 ids, then return on limit 1000.

 With this iterator we build queries using only batch of ids, so find_each will cause relation.where(:id => 1000ids)
 and relation.where(:id => 500ids)

 @param batch_size [Integer] A batch size we want to fetch from DB
 @param attributes_index [Hash{String => Hash}] Indexed hash with data we will be saving
 @yield Code processing the batches