Skip to content

A platform for community discussion. Free, open, simple.

DEV: Update `reply_to_user_id` after bulk imports (#25289)

Gerhard Schlager1a8cf92be172
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