5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/searchkick/process_batch_job.rb', line 5
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?)
delete_ids = record_ids - records.map { |r| r.id.to_s }
delete_records = delete_ids.map { |id| m = klass.new; m.id = id; m }
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
|