~cytrogen/masto-fe

ref: 9bb2fb6b1484c90c5b2c6cc52ce148019e82a3e2 masto-fe/app/lib/importer/public_statuses_index_importer.rb -rw-r--r-- 677 bytes
9bb2fb6b — Claire Change importers to avoid a few inefficiencies (#26721) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

class Importer::PublicStatusesIndexImporter < Importer::BaseImporter
  def import!
    scope.select(:id).find_in_batches(batch_size: @batch_size) do |batch|
      in_work_unit(batch.pluck(:id)) do |status_ids|
        bulk = ActiveRecord::Base.connection_pool.with_connection do
          build_bulk_body(index.adapter.default_scope.where(id: status_ids))
        end

        indexed = bulk.size
        deleted = 0

        Chewy::Index::Import::BulkRequest.new(index).perform(bulk)

        [indexed, deleted]
      end
    end

    wait!
  end

  private

  def index
    PublicStatusesIndex
  end

  def scope
    Status.indexable
  end
end