Commit 8b6d067e2fcbd5b0dc1c6ec3d461c78e4a0711c7

Authored by Andrew Kane
1 parent 45e4eb9e

Don't call minimum twice, and handle no record case better

Showing 1 changed file with 5 additions and 4 deletions   Show diff stats
lib/searchkick/index.rb
... ... @@ -421,10 +421,11 @@ module Searchkick
421 421 # TODO expire Redis key
422 422 primary_key = scope.primary_key
423 423  
424   -
425   - if scope.minimum(primary_key).is_a?(Numeric)
426   - starting_id = scope.minimum(primary_key) || 0
427   - max_id = scope.maximum(primary_key) || 0
  424 + starting_id = scope.minimum(primary_key)
  425 + if starting_id.nil?
  426 + # no records, do nothing
  427 + elsif starting_id.is_a?(Numeric)
  428 + max_id = scope.maximum(primary_key)
428 429 batches_count = ((max_id - starting_id + 1) / batch_size.to_f).ceil
429 430  
430 431 batches_count.times do |i|
... ...