FIX: Stop updating bookmarked column from TopicUser.update_post_action_cache (#10188)

* This is causing issues where sometimes bookmarked is out of sync with what is in the Bookmark table. The BookmarkManager handles updating this column now.
* Add migration to fix bookmarked column that is incorrectly marked false when a Bookmark record exists.
This commit is contained in:
Martin Brennan
2020-07-08 15:27:42 +10:00
committed by GitHub
parent 2e1eafae06
commit 07ad243603
3 changed files with 25 additions and 3 deletions

View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
class FixTopicUserBookmarkedSyncIssues < ActiveRecord::Migration[6.0]
def up
sql = <<~SQL
UPDATE topic_users SET bookmarked = true WHERE id IN (
SELECT topic_users.id
FROM topic_users
INNER JOIN bookmarks ON bookmarks.user_id = topic_users.user_id AND
bookmarks.topic_id = topic_users.topic_id
WHERE NOT topic_users.bookmarked
) AND NOT bookmarked
SQL
DB.exec(sql)
end
def down
raise ActiveRecord::IrreversibleMigration
end
end