acts_as_searchableのreindex!の高速化

acts_as_searchableのreindex!は非常に重いです。
ソースがこんな感じ

        def reindex!
          find(:all).each { |r| r.update_index(true) }
        end

find(:all)とか、平気で実行出来るモデルの様に件数が少ない奴だったらhyperestraierに連動しないですよね。

        def reindex!
          limits = 100
          counts = self.count
          (counts / limits + 1).times do | i |
            find(:all, :offset => (i * limits), :limit => limits ).each { |r| r.update_index(true) }
          end
        end

という訳で、ちょっとずつ分解していく様に変更。


.....してもまだ重かった....。
1件毎に1秒ぐらいのタイムラグがある。
何日かかれば終わるんだーって話ですやね。
update_indexの処理を見てみると、データが既にあれば削除する為に、毎回検索してるみたい。
あー.....まあ、仕方ないよねー。


とりあえず、今回は一回全部消して再度登録したかったので、

        def reindex!
          limits = 100
          counts = self.count
          (counts / limits + 1).times do | i |
            find(:all, :offset => (i * limits), :limit => limits ).each { |r| 
              estraier_connection.put_doc(r.document_object)
       }
          end
        end

とする。
新規にnodeを作ってdevelopmentの利用するnodeをそのnodeにして
development環境でindexを生成させたのです。


処理時間的に2日の量のバッチ→2時間のバッチ。
まあ、そりゃそうだよねー。


と言うか既にreindex!ではなく、create_index!になっている罠。(意味的に)