From adb93716ca7776d6f8bbf8f2680ede45fb267b4e Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 9 Apr 2018 23:30:36 +0530 Subject: [PATCH] FIX: rake task should rebake posts in descending ID order --- lib/tasks/posts.rake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index 6584656f6bc..0148fbcfdf5 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -87,9 +87,12 @@ def rebake_posts(opts = {}) total = Post.count rebaked = 0 - Post.find_each do |post| - rebake_post(post, opts) - print_status(rebaked += 1, total) + # TODO: make this resumable because carrying around 20 million ids in memory is not a great idea long term + Post.order(id: :desc).pluck(:id).in_groups_of(1000, false).each do |batched_post_ids| + Post.order(created_at: :desc).where(id: batched_post_ids).each do |post| + rebake_post(post, opts) + print_status(rebaked += 1, total) + end end SiteSetting.disable_edit_notifications = disable_edit_notifications