I have a Product model:
class Product < ActiveRecord::Base belongs_to :subcategory define_index do # fields indexes subcategory.
Try the following instead:
def set_product_delta_flag Product.update_all ['delta = ?', true], ['subcategory_id = ?', id] Product.index_delta end
A single SQL statement, a single delta re-indexing. Should perform far better :)