Commit 4580fc1aba46766578dd97ffde7f9d337e4ae1af
1 parent
9ecd12ed
Exists in
master
and in
19 other branches
Added import_batch method for cleaner code
Showing
2 changed files
with
9 additions
and
7 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_scope(Searchkick.load_records(klass, record_ids), method_name: method_name, batch: true, batch_id: batch_id) | |
9 | + index.import_batch(Searchkick.load_records(klass, record_ids), method_name: method_name, batch_id: batch_id) | |
10 | 10 | end |
11 | 11 | end |
12 | 12 | end | ... | ... |
lib/searchkick/index.rb
... | ... | @@ -247,16 +247,18 @@ module Searchkick |
247 | 247 | end |
248 | 248 | end |
249 | 249 | |
250 | - def import_scope(scope, resume: false, method_name: nil, async: false, batch: false, batch_id: nil, full: false) | |
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) | |
251 | 256 | batch_size = @options[:batch_size] || 1000 |
252 | 257 | |
253 | 258 | # use scope for import |
254 | 259 | scope = scope.search_import if scope.respond_to?(:search_import) |
255 | 260 | |
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 | |
261 | + if full && async | |
260 | 262 | if scope.respond_to?(:primary_key) |
261 | 263 | # TODO expire Redis key |
262 | 264 | primary_key = scope.primary_key |
... | ... | @@ -422,7 +424,7 @@ module Searchkick |
422 | 424 | end |
423 | 425 | end |
424 | 426 | |
425 | - def import_or_update(records, method_name, async) | |
427 | + def import_or_update(records, method_name, async = false) | |
426 | 428 | if records.any? |
427 | 429 | if async |
428 | 430 | Searchkick::BulkReindexJob.perform_later( | ... | ... |