Sha256: 67baa0b320cda3409a716ec02ed2ee539832988f9e9fb7c3f56a0d1b3b537ef4

Contents?: true

Size: 758 Bytes

Versions: 16

Compression:

Stored size: 758 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) if records.any?
        index.bulk_delete(delete_records) if delete_records.any?
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
searchkick-hooopo-2.4.1 lib/searchkick/process_batch_job.rb
searchkick-hooopo-2.4.0 lib/searchkick/process_batch_job.rb
searchkick-2.4.0 lib/searchkick/process_batch_job.rb
searchkick-hooopo-2.3.5 lib/searchkick/process_batch_job.rb
searchkick-2.3.2 lib/searchkick/process_batch_job.rb
searchkick-hooopo-2.3.4 lib/searchkick/process_batch_job.rb
searchkick-2.3.1 lib/searchkick/process_batch_job.rb
searchkick-hooopo-2.3.3 lib/searchkick/process_batch_job.rb
searchkick-hooopo-2.3.2 lib/searchkick/process_batch_job.rb
searchkick-hooopo-2.3.1 lib/searchkick/process_batch_job.rb
searchkick-hooopo-2.3.0 lib/searchkick/process_batch_job.rb
searchkick-2.3.0 lib/searchkick/process_batch_job.rb
searchkick-2.2.1 lib/searchkick/process_batch_job.rb
searchkick-2.2.0 lib/searchkick/process_batch_job.rb
searchkick-2.1.1 lib/searchkick/process_batch_job.rb
searchkick-2.1.0 lib/searchkick/process_batch_job.rb