From 4fd4b579af190ce80d5700e8fe6ef6ed74284454 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 11:20:32 +0800 Subject: [PATCH] fix rake --- lib/tasks/course_board_message_count.rake | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/tasks/course_board_message_count.rake b/lib/tasks/course_board_message_count.rake index d1ac5524d..35e439403 100644 --- a/lib/tasks/course_board_message_count.rake +++ b/lib/tasks/course_board_message_count.rake @@ -5,13 +5,15 @@ namespace :course_board do logger("Current transfer board id: #{board.id} ~") root_subquery = board.messages.where(parent_id: nil).reorder(nil).pluck(:id) - next if root_subquery.blank? - children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id) - next if children_subquery.blank? - second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id) + if root_subquery.present? + children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id) + if children_subquery.present? + second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id) - ids = children_subquery.concat(second_children_subquery).uniq - Message.where(id: ids).update_all(board_id: board.id) + ids = children_subquery.concat(second_children_subquery).uniq + Message.where(id: ids).update_all(board_id: board.id) + end + end Board.reset_counters(board.id, :messages) logger("transfer success ~")