accounts_index_importer.rb 657 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 = Chewy::Index::Import::BulkBuilder.new(index, to_index: accounts).bulk_body
  7. indexed = bulk.count { |entry| entry[:index] }
  8. deleted = bulk.count { |entry| entry[:delete] }
  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