Commit 1008590ef9bb7f7df69710dd92c9a68940812220

Authored by Andrew Kane
1 parent 6fc6638b

Simplified import_scope logic [skip ci]

lib/searchkick/bulk_indexer.rb
... ... @@ -6,7 +6,12 @@ module Searchkick
6 6 @index = index
7 7 end
8 8  
9   - def import_scope(relation, resume: false, method_name: nil, async: false, batch: false, batch_id: nil, full: false, scope: nil, mode: nil)
  9 + def import_batch(relation, method_name: nil, batch_id: nil)
  10 + import_or_update relation.to_a, method_name, :inline, false
  11 + Searchkick.with_redis { |r| r.srem(batches_key, batch_id) } if batch_id
  12 + end
  13 +
  14 + def import_scope(relation, resume: false, method_name: nil, async: false, full: false, scope: nil, mode: nil)
10 15 if scope
11 16 relation = relation.send(scope)
12 17 elsif relation.respond_to?(:search_import)
... ... @@ -15,10 +20,7 @@ module Searchkick
15 20  
16 21 mode ||= (async ? :async : :inline)
17 22  
18   - if batch
19   - import_or_update relation.to_a, method_name, mode, full
20   - Searchkick.with_redis { |r| r.srem(batches_key, batch_id) } if batch_id
21   - elsif full && async
  23 + if full && async
22 24 full_reindex_async(relation)
23 25 elsif relation.respond_to?(:find_in_batches)
24 26 if resume
... ...
lib/searchkick/bulk_reindex_job.rb
... ... @@ -4,12 +4,11 @@ module Searchkick
4 4  
5 5 def perform(class_name:, record_ids: nil, index_name: nil, method_name: nil, batch_id: nil, min_id: nil, max_id: nil)
6 6 klass = class_name.constantize
7   - index = index_name ? Searchkick::Index.new(index_name, **klass.searchkick_options) : klass.searchkick_index
  7 + index = index_name ? Searchkick::Index.new(index_name, klass.searchkick_options) : klass.searchkick_index
8 8 record_ids ||= min_id..max_id
9   - index.import_scope(
  9 + index.send(:bulk_indexer).import_batch(
10 10 Searchkick.load_records(klass, record_ids),
11 11 method_name: method_name,
12   - batch: true,
13 12 batch_id: batch_id
14 13 )
15 14 end
... ...