Commit 022c054edcd4954a73fb2dae6a742da0bcdfd86f
1 parent
013ef3cc
Exists in
master
and in
19 other branches
Switch to find_in_batches and find the first PK to see if's a Numeric
- Unsure of the sql_type_metadata consistency and possible types, easier to find the minimum PK and see if its type `Numeric` - `#in_batches` is better, but only introduced in rails5. Switch to less performant `#find_in_batches` and grab each ID with ruby :( Such slow!
Showing
1 changed file
with
3 additions
and
3 deletions
Show diff stats
lib/searchkick/index.rb
... | ... | @@ -422,7 +422,7 @@ module Searchkick |
422 | 422 | primary_key = scope.primary_key |
423 | 423 | |
424 | 424 | |
425 | - if %i(integer float decimal).include?(scope.column_for_attribute(primary_key).sql_type_metadata) | |
425 | + if scope.minimum(primary_key).is_a?(Numeric) | |
426 | 426 | starting_id = scope.minimum(primary_key) || 0 |
427 | 427 | max_id = scope.maximum(primary_key) || 0 |
428 | 428 | batches_count = ((max_id - starting_id + 1) / batch_size.to_f).ceil |
... | ... | @@ -433,10 +433,10 @@ module Searchkick |
433 | 433 | bulk_reindex_job scope, batch_id, min_id: min_id, max_id: min_id + batch_size - 1 |
434 | 434 | end |
435 | 435 | else |
436 | - scope.in_batches(of: batch_size).each_with_index do |batch, i| | |
436 | + scope.find_in_batches(batch_size: batch_size).each_with_index do |batch, i| | |
437 | 437 | batch_id = i + 1 |
438 | 438 | |
439 | - bulk_reindex_job scope, batch_id, record_ids: batch.pluck(primary_key) | |
439 | + bulk_reindex_job scope, batch_id, record_ids: batch.map { |record| record.id.to_s } | |
440 | 440 | end |
441 | 441 | end |
442 | 442 | else | ... | ... |