Class: SunspotOffline::Sidekiq::IndexWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/sunspot_offline/sidekiq/index_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(model_class, scope) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sunspot_offline/sidekiq/index_worker.rb', line 8

def perform(model_class, scope)
  klass = model_class.classify.constantize
  if klass.searchable?
    if scope.is_a?(Array)
      scope.each_slice(1000) { |slice| Sunspot.index(klass.where(id: slice)) }
    elsif scope.is_a?(Hash)
      klass.atomic_update(scope.with_indifferent_access)
    else
      klass.where(id: scope).take&.index
    end
  end
end