-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Avoid syncing user bookmarks for users that are getting destroyed #26338
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed internally we need to collect all the destroyed topic IDs and run the SyncTopicUserBookmarked job at the end of UserDestroyer (we need to modify the job for this)
); | ||
|
||
DROP TABLE tmp_sync_topic_user_bookmarks; | ||
SET bookmarked = CASE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted internally, the perf of this worries me a bit; the tmp_sync_topic_user_bookmarks
way was done because there are potentially a lot of records changing here.
DB.exec(<<~SQL, topic_id: args[:topic_id]) | ||
SELECT bookmarks.user_id, COUNT(*) | ||
INTO TEMP TABLE tmp_sync_topic_user_bookmarks | ||
bookmarks_exist = DB.exec(<<~SQL, topic_id: args[:topic_id]) > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a query for a value now, this should be DB.query_single
. IIRC the return value of exec
is based on success of the query, not the actually return value.
WHERE topic_users.user_id = tmp_sync_topic_user_bookmarks.user_id AND | ||
topic_users.topic_id = :topic_id AND | ||
tmp_sync_topic_user_bookmarks.count > 0; | ||
return unless bookmarks_exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return unless bookmarks_exist | |
return if !bookmarks_exist |
This is a Sam special :P
5e8c5ea
to
0a0eda1
Compare
@martin-brennan @nattsw do we still want to get this merged? |
When a user is destroyed via
UserDestroyer
, it first gets itsBookmark
s deleted, then itsPost
s.In the
PostDestroyer
, theSyncTopicUserBookmarked
job gets called to make sure orphan bookmarks are deleted if the post is a topic. However, this job is not needed when a user is getting destroyed.This PR adds an
opt
that indicates toPostDestroyer
that this job doesn't need to be scheduled. This PR also optimises the sync job to skip topics where there are no bookmarks.No bookmarks
Five bookmarks