Commit f9713e118cd3548e3f064785b2d628ec4564d0f6
1 parent
0742db8a
Exists in
master
and in
19 other branches
Revert "Added import_batch method for cleaner code"
This reverts commit 4580fc1aba46766578dd97ffde7f9d337e4ae1af.
Showing
2 changed files
with
7 additions
and
9 deletions
Show diff stats
lib/searchkick/bulk_reindex_job.rb
... | ... | @@ -6,7 +6,7 @@ module Searchkick |
6 | 6 | klass = class_name.constantize |
7 | 7 | index = index_name ? Searchkick::Index.new(index_name) : klass.searchkick_index |
8 | 8 | record_ids ||= min_id..max_id |
9 | - index.import_batch(Searchkick.load_records(klass, record_ids), method_name: method_name, batch_id: batch_id) | |
9 | + index.import_scope(Searchkick.load_records(klass, record_ids), method_name: method_name, batch: true, batch_id: batch_id) | |
10 | 10 | end |
11 | 11 | end |
12 | 12 | end | ... | ... |
lib/searchkick/index.rb
... | ... | @@ -247,18 +247,16 @@ module Searchkick |
247 | 247 | end |
248 | 248 | end |
249 | 249 | |
250 | - def import_batch(scope, method_name: nil, batch_id: nil) | |
251 | - import_or_update scope.to_a, method_name | |
252 | - Searchkick.redis.srem(batches_key, batch_id) if batch_id && Searchkick.redis | |
253 | - end | |
254 | - | |
255 | - def import_scope(scope, resume: false, method_name: nil, async: false, full: false) | |
250 | + def import_scope(scope, resume: false, method_name: nil, async: false, batch: false, batch_id: nil, full: false) | |
256 | 251 | batch_size = @options[:batch_size] || 1000 |
257 | 252 | |
258 | 253 | # use scope for import |
259 | 254 | scope = scope.search_import if scope.respond_to?(:search_import) |
260 | 255 | |
261 | - if full && async | |
256 | + if batch | |
257 | + import_or_update scope.to_a, method_name, async | |
258 | + Searchkick.redis.srem(batches_key, batch_id) if batch_id && Searchkick.redis | |
259 | + elsif full && async | |
262 | 260 | if scope.respond_to?(:primary_key) |
263 | 261 | # TODO expire Redis key |
264 | 262 | primary_key = scope.primary_key |
... | ... | @@ -424,7 +422,7 @@ module Searchkick |
424 | 422 | end |
425 | 423 | end |
426 | 424 | |
427 | - def import_or_update(records, method_name, async = false) | |
425 | + def import_or_update(records, method_name, async) | |
428 | 426 | if records.any? |
429 | 427 | if async |
430 | 428 | Searchkick::BulkReindexJob.perform_later( | ... | ... |