mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 20:08:26 +00:00
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:
parent
2e1eafae06
commit
07ad243603
@ -224,7 +224,7 @@ class PostAction < ActiveRecord::Base
|
|||||||
topic_id = Post.with_deleted.where(id: post_id).pluck_first(:topic_id)
|
topic_id = Post.with_deleted.where(id: post_id).pluck_first(:topic_id)
|
||||||
|
|
||||||
# topic_user
|
# topic_user
|
||||||
if [:like, :bookmark].include? post_action_type_key
|
if post_action_type_key == :like
|
||||||
TopicUser.update_post_action_cache(user_id: user_id,
|
TopicUser.update_post_action_cache(user_id: user_id,
|
||||||
topic_id: topic_id,
|
topic_id: topic_id,
|
||||||
post_action_type: post_action_type_key)
|
post_action_type: post_action_type_key)
|
||||||
|
@ -22,6 +22,10 @@ class TopicUser < ActiveRecord::Base
|
|||||||
level(topic_id, :watching)
|
level(topic_id, :watching)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def topic_bookmarks
|
||||||
|
Bookmark.where(topic: topic, user: user)
|
||||||
|
end
|
||||||
|
|
||||||
# Class methods
|
# Class methods
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
@ -369,13 +373,11 @@ class TopicUser < ActiveRecord::Base
|
|||||||
action_type = opts[:post_action_type]
|
action_type = opts[:post_action_type]
|
||||||
|
|
||||||
action_type_name = "liked" if action_type == :like
|
action_type_name = "liked" if action_type == :like
|
||||||
action_type_name = "bookmarked" if action_type == :bookmark
|
|
||||||
|
|
||||||
raise ArgumentError, "action_type" if action_type && !action_type_name
|
raise ArgumentError, "action_type" if action_type && !action_type_name
|
||||||
|
|
||||||
unless action_type_name
|
unless action_type_name
|
||||||
update_post_action_cache(opts.merge(post_action_type: :like))
|
update_post_action_cache(opts.merge(post_action_type: :like))
|
||||||
update_post_action_cache(opts.merge(post_action_type: :bookmark))
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user