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

This commit is contained in:
Gerhard Schlager 2024-01-17 20:47:01 +01:00 committed by GitHub
parent 6a205ea0a5
commit 1a8cf92be1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 1 deletions

View File

@ -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