My journey into a massive posts rebake job

This is now done via:

We no longer carry post ids in memory and the rebake task can be resumed by running posts:rebake_uncooked_posts.

One caveat here is that the resume task will not rebake posts in reverse order (i.e. the sort order will be id ascending).

「いいね!」 6

So @techAPJ, if I need to trigger a rebake of every post on a Discourse install, is @pfaffman’s method the proper one to use?

If you need to rebake all posts instantly then run bundle exec rake posts:rebake.

Post.update_all("baked_version = NULL") will rebake 100 posts (by default) every 15 minutes.

「いいね!」 4

Thanks, Arpit.

FYI, I encountered some performance issues with that approach, so I went with this, which alleviated the problem and resulted in the same outcome:

Post.in_batches.update_all('baked_version = NULL')

「いいね!」 6

@techAPJ I have a dummy question. Where do you run this command? After entering the app?

It tells me

bash: syntax error near unexpected token ''baked_version = NULL''

./launcher enter app
rails c
Post.in_batches.update_all('baked_version = NULL')
「いいね!」 6

Would the batch method be suitable for a large amount of rebakes?

2851000 / 27182220 ( 10.5%)

This our current process after starting it yesterday with the normal rebake command, it seems to tick about 1000 every 3 seconds. We are very close to the end of our import journey and testing, and I just wanted to make sure there was a more proper way to rebake a large site before we settled on this slower method.

「いいね!」 1

この in_batches バージョンがどのように機能するか、誰か説明してもらえますか。おそらくバッチで再ベイクを実行するのでしょうが、上記の投稿では、デフォルトで100個ずつ15分ごとに再ベイクを実行すると述べられています。

200万件の再ベイクジョブがあり、最善の方法を模索しています。ジョブに緊急性はありませんが、長時間実行されるジョブによって通常の運用や管理運用(バックアップなど)が影響を受けないようにしたいと考えています。

そして今、私はこの投稿を読みました:Rebaked all my posts, but what's it doing now? これは、再ベイクタスクが実際には再ベイクしているのではなく、再ベイクのためにマークしているだけであることを示しています(このマークはどのように行われるのですか?)。プロセスが非常に遅いため、投稿を再ベイクのためにマークするだけでこれほど時間がかかることを本当に信じがたいです。

より高速なサーバーに移行してください。

このプロセスがサイトに過負荷をかけないことに感謝してください。全体的な目的は、このプロセスがリソースを過剰に消費しないようにし、プロセス中にサイトの応答性を維持することです。

ソースを参照することは常に良い考えです。

「いいね!」 2

確かに、マーキングは非常に迅速に行われるはずです。そして、rebake_post はクッキングを呼び出すように見えます。これの一部または結果として、非同期タスクが発生しているのでしょうか?

はい、もちろんです。ジョブのセットを生成するジョブです。

理想的な解決策ではありませんが、別の方法を見つけました!

独自の再ベーカーを作成しました。これは1000倍高速なので、1ヶ月かかる代わりに数分で済みます。

データベース挿入の直前に再ベークするので、再ベークのコストはDB挿入時間内に消えます。

「いいね!」 1

あ、わかりました。あなたのコンテキストは知りませんでした。
はい、これは本番環境向けに書かれています。

「いいね!」 1

興味本位で、何をしたか教えていただけますか?

インポートされたすべての投稿をスキャンして、どのようなマークアップ/スマイリーが含まれているかを見つけるプログラムを作成しました。次に、生の投稿をHTMLにベイクしてデータベースを直接更新する別のプログラムを作成しました。