Skip to content

AO3-3601 Fix pseud bookmark reindex#5734

Open
pmonfort wants to merge 3 commits intootwcode:masterfrom
pmonfort:AO3-3601-fix-pseud-bookmark-reindex
Open

AO3-3601 Fix pseud bookmark reindex#5734
pmonfort wants to merge 3 commits intootwcode:masterfrom
pmonfort:AO3-3601-fix-pseud-bookmark-reindex

Conversation

@pmonfort
Copy link
Copy Markdown
Contributor

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-3601

Purpose

When a pseud is deleted and its bookmarks are transferred to the default pseud, Pseud#change_bookmarks_ownership uses update_all to reassign the bookmarks.
Since update_all skips ActiveRecord callbacks, the bookmarks are never reindexed in Elasticsearch, so they don't appear on the default pseud's bookmark page.

This PR enqueues the transferred bookmark IDs for reindexing after the update_all, and modernizes the raw SQL strings to use hash conditions.

Testing Instructions

  1. Create a pseud and use it to bookmark several works
  2. Delete the pseud and choose "Transfer these bookmarks to the default pseud"
  3. Verify that the bookmarks appear on the default pseud's bookmark page

Credit

Pablo Monfort (he/him)

@sarken sarken changed the title Ao3 3601 fix pseud bookmark reindex AO3-3601 Fix pseud bookmark reindex Apr 15, 2026
Comment thread app/models/pseud.rb Outdated
Comment on lines +402 to +404
bookmark_ids = Bookmark.where(pseud_id: id).ids
Bookmark.where(pseud_id: id).update_all(pseud_id: user.default_pseud.id)
IndexQueue.enqueue_ids(Bookmark, bookmark_ids, :main) if bookmark_ids.present?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, could you create a scope to be used by both queries? I'm thinking along the lines of

Suggested change
bookmark_ids = Bookmark.where(pseud_id: id).ids
Bookmark.where(pseud_id: id).update_all(pseud_id: user.default_pseud.id)
IndexQueue.enqueue_ids(Bookmark, bookmark_ids, :main) if bookmark_ids.present?
bookmarks = Bookmark.where(pseud_id: id)
bookmarks.update_all(pseud_id: user.default_pseud.id)
IndexQueue.enqueue_ids(Bookmark, bookmarks.ids, :main) if bookmark_ids.present?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, makes sense! 👍

Comment thread spec/models/pseud_spec.rb Outdated
let(:pseud) { create(:pseud, user: user) }
let(:default_pseud) { user.default_pseud }

let!(:bookmarks) { Array.new(2) { create(:bookmark, pseud: pseud) } }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(https://thoughtbot.github.io/factory_bot/building-or-creating-multiple-records/summary.html)

Suggested change
let!(:bookmarks) { Array.new(2) { create(:bookmark, pseud: pseud) } }
let!(:bookmarks) { create_list(:bookmark, 2, pseud: pseud) }

@pmonfort
Copy link
Copy Markdown
Contributor Author

@brianjaustin Thanks for your review! I've updated the code with both suggestions. Let me know how it looks.

@pmonfort pmonfort requested a review from brianjaustin April 19, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants