Commit ad006fd9df5498907b11ddc535db92be2296c9cf

Authored by Andrew Kane
1 parent e09d4473

Changed delete to delete_missing [skip ci]

lib/searchkick/bulk_reindex_job.rb
@@ -2,7 +2,7 @@ module Searchkick @@ -2,7 +2,7 @@ module Searchkick
2 class BulkReindexJob < ActiveJob::Base 2 class BulkReindexJob < ActiveJob::Base
3 queue_as :searchkick 3 queue_as :searchkick
4 4
5 - def perform(class_name:, record_ids: nil, index_name: nil, method_name: nil, batch_id: nil, min_id: nil, max_id: nil, delete: false) 5 + def perform(class_name:, record_ids: nil, index_name: nil, method_name: nil, batch_id: nil, min_id: nil, max_id: nil, delete_missing: false)
6 klass = class_name.constantize 6 klass = class_name.constantize
7 index = index_name ? Searchkick::Index.new(index_name) : klass.searchkick_index 7 index = index_name ? Searchkick::Index.new(index_name) : klass.searchkick_index
8 record_ids ||= min_id..max_id 8 record_ids ||= min_id..max_id
@@ -12,7 +12,7 @@ module Searchkick @@ -12,7 +12,7 @@ module Searchkick
12 method_name: method_name, 12 method_name: method_name,
13 batch: true, 13 batch: true,
14 batch_id: batch_id, 14 batch_id: batch_id,
15 - delete: delete, 15 + delete_missing: delete_missing,
16 record_ids: record_ids 16 record_ids: record_ids
17 ) 17 )
18 end 18 end
lib/searchkick/index.rb
@@ -247,14 +247,14 @@ module Searchkick @@ -247,14 +247,14 @@ module Searchkick
247 end 247 end
248 end 248 end
249 249
250 - def import_scope(scope, resume: false, method_name: nil, async: false, batch: false, batch_id: nil, full: false, delete: false, record_ids: nil) 250 + def import_scope(scope, resume: false, method_name: nil, async: false, batch: false, batch_id: nil, full: false, delete_missing: false, record_ids: nil)
251 batch_size = @options[:batch_size] || 1000 251 batch_size = @options[:batch_size] || 1000
252 252
253 # use scope for import 253 # use scope for import
254 scope = scope.search_import if scope.respond_to?(:search_import) 254 scope = scope.search_import if scope.respond_to?(:search_import)
255 255
256 if batch 256 if batch
257 - import_or_update scope.to_a, method_name, async, delete, record_ids, scope.model 257 + import_or_update scope.to_a, method_name, async, delete_missing, record_ids, scope.model
258 Searchkick.redis.srem(batches_key, batch_id) if batch_id && Searchkick.redis 258 Searchkick.redis.srem(batches_key, batch_id) if batch_id && Searchkick.redis
259 elsif full && async 259 elsif full && async
260 if scope.respond_to?(:primary_key) 260 if scope.respond_to?(:primary_key)
@@ -422,7 +422,7 @@ module Searchkick @@ -422,7 +422,7 @@ module Searchkick
422 end 422 end
423 end 423 end
424 424
425 - def import_or_update(records, method_name, async, delete = false, record_ids = nil, klass = nil) 425 + def import_or_update(records, method_name, async, delete_missing = false, record_ids = nil, klass = nil)
426 if records.any? 426 if records.any?
427 if async 427 if async
428 Searchkick::BulkReindexJob.perform_later( 428 Searchkick::BulkReindexJob.perform_later(
@@ -436,7 +436,7 @@ module Searchkick @@ -436,7 +436,7 @@ module Searchkick
436 records = records.select(&:should_index?) 436 records = records.select(&:should_index?)
437 437
438 delete_records = 438 delete_records =
439 - if delete 439 + if delete_missing
440 # determine which records to delete 440 # determine which records to delete
441 (record_ids - records.map { |r| r.id.to_s }).map { |id| m = klass.new; m.id = id; m } 441 (record_ids - records.map { |r| r.id.to_s }).map { |id| m = klass.new; m.id = id; m }
442 else 442 else
lib/searchkick/process_batch_job.rb
@@ -7,7 +7,7 @@ module Searchkick @@ -7,7 +7,7 @@ module Searchkick
7 Searchkick::BulkReindexJob.perform_now( 7 Searchkick::BulkReindexJob.perform_now(
8 class_name: class_name, 8 class_name: class_name,
9 record_ids: record_ids, 9 record_ids: record_ids,
10 - delete: true 10 + delete_missing: true
11 ) 11 )
12 end 12 end
13 end 13 end