class Backfills::NormalizeTitles
def call
Snip.select(:id, :title).find_each(batch_size: 2000) do |snip|
normalized = snip.title.to_s.strip
next if normalized == snip.title
Snip.where(id: snip.id).update_all(title: normalized, updated_at: Time.current)
end
end
end
Backfills often fail because we accidentally load full records and associations. Use select to fetch only needed columns and find_each to keep memory flat. This is basic, but it’s where outages come from.