Sha256: 537199183d7cfa29be17820c0ef3c54711cd1079005d49c52535185b5b857275

Contents?: true

Size: 719 Bytes

Versions: 1

Compression:

Stored size: 719 Bytes

Contents

module Searchkick
  class ProcessBatchJob < ActiveJob::Base
    queue_as :searchkick

    def perform(class_name:, record_ids:)
      klass = class_name.constantize
      scope = Searchkick.load_records(klass, record_ids)
      scope = scope.search_import if scope.respond_to?(:search_import)
      records = scope.select(&:should_index?)

      # determine which records to delete
      delete_ids = record_ids - records.map { |r| r.id.to_s }
      delete_records = delete_ids.map { |id| m = klass.new; m.id = id; m }

      # bulk reindex
      index = klass.searchkick_index
      Searchkick.callbacks(:bulk) do
        index.bulk_index(records)
        index.bulk_delete(delete_records)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
searchkick-2.0.4 lib/searchkick/process_batch_job.rb