public_statuses_index_importer.rb 690 B

1234567891011121314151617181920212223242526272829303132
  1. # frozen_string_literal: true
  2. class Importer::PublicStatusesIndexImporter < Importer::BaseImporter
  3. def import!
  4. scope.select(:id).find_in_batches(batch_size: @batch_size) do |batch|
  5. in_work_unit(batch.pluck(:id)) do |status_ids|
  6. bulk = ActiveRecord::Base.connection_pool.with_connection do
  7. build_bulk_body(index.adapter.default_scope.where(id: status_ids))
  8. end
  9. indexed = bulk.size
  10. deleted = 0
  11. Chewy::Index::Import::BulkRequest.new(index).perform(bulk)
  12. [indexed, deleted]
  13. end
  14. end
  15. wait!
  16. end
  17. private
  18. def index
  19. PublicStatusesIndex
  20. end
  21. def scope
  22. Status.indexable.reorder(nil)
  23. end
  24. end