module Jekyll::Algolia::Indexer

def self.run_diff_mode(records)

of all records in the index, but it will consume less operations.
updated. It will be a bit slower as it will first need to get the list
remove old content from it. It won't touch records that haven't been
The `diff` indexing mode will only push new content to the index and

records - Array of local records

Public: Index content following the `diff` indexing mode
def self.run_diff_mode(records)
  index = index(Configurator.index_name)
  # Update settings
  update_settings(index, Configurator.settings)
  # Getting list of objectID in remote and locally
  remote_ids = remote_object_ids(index)
  local_ids = local_object_ids(records)
  old_records_ids = remote_ids - local_ids
  new_records_ids = local_ids - remote_ids
  if old_records_ids.empty? && new_records_ids.empty?
    Logger.log('I:Nothing to index. Your content is already up to date.')
    return
  end
  Logger.log('I:Pushing records to Algolia...')
  # Delete remote records that are no longer available locally
  delete_records_by_id(index, old_records_ids)
  # Add only records that are not yet already in the remote
  new_records = records.select do |record|
    new_records_ids.include?(record[:objectID])
  end
  update_records(index, new_records)
  Logger.log('I:✔ Indexing complete')
end