FIX: Topic user bookmarked column is out of sync after post moves (#12612)

When posts are moved from one topic to another, the `topic_user.bookmarked` column for all users in the new and the old topic needs to be resynced, for example because a user bookmarks post 12 in topic 1, then it is moved to topic 2, the topic_user record for topic 1 should no longer be bookmarked. A background job has been added to sync the column for a specified topic, or for no topic at all, which does it for all topics like the migration.

Also includes a migration that we have run in the past to fix bad data.

----

This has been addressed in other places in the past:

https://github.com/discourse/discourse/pull/10211
https://github.com/discourse/discourse/pull/10188
This commit is contained in:
Martin Brennan
2021-04-14 09:10:53 +10:00
committed by GitHub
parent 71475a1a01
commit 66d17fdd6b
5 changed files with 153 additions and 0 deletions

View File

@@ -494,6 +494,11 @@ class PostMover
def update_bookmarks
Bookmark.where(post_id: post_ids).update_all(topic_id: @destination_topic.id)
DB.after_commit do
Jobs.enqueue(:sync_topic_user_bookmarked, topic_id: @original_topic.id)
Jobs.enqueue(:sync_topic_user_bookmarked, topic_id: @destination_topic.id)
end
end
def watch_new_topic