From 1a8cf92be172fe059bc66e4cbd0f06035211598d Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 17 Jan 2024 20:47:01 +0100 Subject: [PATCH] DEV: Update `reply_to_user_id` after bulk imports (#25289) --- lib/tasks/import.rake | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index d94a48d7ea0..89b8f253b89 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -335,7 +335,7 @@ def update_user_stats end def update_posts - log "Updating posts..." + log "Updating post reply counts..." DB.exec <<-SQL WITH Y AS ( @@ -359,6 +359,19 @@ def update_posts # FROM X # WHERE id = X.post_id # AND COALESCE(reply_to_user_id, -9999) <> X.user_id + + log "Updating post reply_to_user_id..." + + DB.exec <<~SQL + UPDATE posts AS replies + SET reply_to_user_id = replies.user_id + FROM posts + WHERE posts.topic_id = replies.topic_id + AND posts.post_number = replies.reply_to_post_number + AND replies.reply_to_post_number IS NOT NULL + AND replies.reply_to_user_id IS NULL + AND replies.post_number <> replies.reply_to_post_number + SQL end def update_topics