From e9d92da9eebc14015efa381e584e90ded07f78eb Mon Sep 17 00:00:00 2001 From: Arpit Jalan <arpit@techapj.com> Date: Tue, 8 May 2018 15:14:19 +0530 Subject: [PATCH] minor optimizations to categories:move_topics rake task --- lib/tasks/categories.rake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tasks/categories.rake b/lib/tasks/categories.rake index 920b3255ee5..407bf65f741 100644 --- a/lib/tasks/categories.rake +++ b/lib/tasks/categories.rake @@ -10,9 +10,12 @@ task "categories:move_topics", [:from_category, :to_category] => [:environment] from_category = Category.find(from_category_id) to_category = Category.find(to_category_id) - if from_category && to_category - Topic.where(category_id: from_category_id).update_all(category_id: to_category_id) + if from_category.present? && to_category.present? + puts "Moving topics from #{from_category.slug} to #{to_category.slug}..." + Topic.where(category_id: from_category.id).update_all(category_id: to_category.id) from_category.update_attribute(:topic_count, 0) + + puts "Updating category stats..." Category.update_stats end