FIX: mark posted as true for post authors in the TopicUser table during ensure_consistency task (#20473)

The ensure_consistency rake task was not marking posted as true for post authors in the TopicUser table, post migration. Create another step to set posted='t'.
This commit is contained in:
Constanza 2023-02-28 20:45:32 -04:00 committed by GitHub
parent 8fec1a412b
commit c051992098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,6 +22,7 @@ task "import:ensure_consistency" => :environment do
update_users
update_groups
update_tag_stats
update_topic_users
create_category_definitions
log "Done!"
@ -29,6 +30,10 @@ end
MS_SPEND_CREATING_POST ||= 5000
# -- TODO: We need to check the queries are actually adding/updating the necessary
# data, post migration. The ON CONFLICT DO NOTHING may cause the clauses to be ignored
# when we actually need them to run.
def insert_post_timings
log "Inserting post timings..."
@ -415,6 +420,29 @@ def update_tag_stats
Tag.ensure_consistency!
end
def update_topic_users
log "Updating topic users..."
DB.exec <<-SQL
WITH X AS (
SELECT p.topic_id
, p.user_id
FROM posts p
JOIN topics t ON t.id = p.topic_id
WHERE p.deleted_at IS NULL
AND t.deleted_at IS NULL
AND NOT p.hidden
AND t.visible
)
UPDATE topic_users tu
SET posted = 't'
FROM X
WHERE tu.topic_id = X.topic_id
AND tu.user_id = X.user_id
AND posted = 'f'
SQL
end
def create_category_definitions
log "Creating category definitions"
Category.ensure_consistency!