about summary refs log tree commit diff
path: root/lib/tasks/monsterfork.rake
blob: 00a0eaedb8d51a064b769c0eaaef679003866319 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
namespace :monsterfork do
  desc '(Re-)Index statuses for search.'
  task index_statuses: :environment do
    include TextHelper

    i = 0
    total = Status.count

    Status.find_in_batches do |statuses|
      ActiveRecord::Base.logger.info("Indexing status #{1+i} of #{total}.")
      ActiveRecord::Base.logger.silence do
        i += statuses.count
        statuses.each do |s|
          begin
            next if s.destroyed?
            s.update_column(:normalized_text, normalize_status(s, cache: false))
          rescue rescue ActiveRecord::RecordNotFound
            true
          end
        end
      end
    end
  end
end