accounts_index_importer.rb 545 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class Importer::AccountsIndexImporter < Importer::BaseImporter
  3. def import!
  4. scope.includes(:account_stat).find_in_batches(batch_size: @batch_size) do |tmp|
  5. in_work_unit(tmp) do |accounts|
  6. bulk = build_bulk_body(accounts)
  7. indexed = bulk.size
  8. deleted = 0
  9. Chewy::Index::Import::BulkRequest.new(index).perform(bulk)
  10. [indexed, deleted]
  11. end
  12. end
  13. wait!
  14. end
  15. private
  16. def index
  17. AccountsIndex
  18. end
  19. def scope
  20. Account.searchable
  21. end
  22. end