after_commit(if: :persisted?) { ItemsIndexing.perform_later(items) } end # /app/jobs/items_indexing.rb class ItemsIndexing < ActiveJob::Base def perform(items) items.find_in_batches(batch_size: 50) do |group| Sunspot.batch { group.each(&:perform_index) } end end end