Skip to content

AO3-7627 Eager load series blurb associations on index - #6077

Open
pmonfort wants to merge 2 commits into
otwcode:masterfrom
pmonfort:AO3-7627
Open

pmonfort wants to merge 2 commits into
otwcode:masterfrom
pmonfort:AO3-7627

Conversation

@pmonfort

@pmonfort pmonfort commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Issue

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

Purpose

Every series blurb on the index ran ~7 queries (tags, byline pseuds/users, counts, dates, bookmarks), and unlike work blurbs there is no fragment cache, so a page of 20 series ran ~140 queries on every render.

This PR:

  • Changes for_blurb to preload({ pseuds: :user }, works: :tags) and chains it in SeriesController#index. preload instead of includes because the index relation carries the string join with GROUP BY from exclude_anonymous, and includes could switch to a single-query eager load and break the paginated query.
  • Makes the blurb methods (tag_groups, visible_work_count, revised_at, word counts) filter the preloaded works in Ruby when the association is loaded, mirroring the original SQL exactly; otherwise the original SQL runs unchanged, so #show keeps its current behavior. revised_at uses a Ruby mirror of Work.visible_to_user.
  • Memoizes tag_groups (called three times per blurb) and switches the view to the existing cached public_bookmark_count, the one remaining per-series query.
  • Adds model specs asserting preloaded and SQL branches return the same results for guests, users and admins, plus edge cases. The n_plus_one_control request specs are in the first commit on this branch.

Note on pre-existing behavior: visible_work_count for guests counts works hidden by an admin, same as the original SQL. This PR aims for parity, not behavior changes, so it keeps that as is.

Testing Instructions

Series listings (a user's series page, a fandom's series listing) should show the same blurbs as before:

  • Byline
  • Fandoms and tag list
  • Dates
  • Words and works counts

The bookmark count in the blurb is now cached for up to 2 hours (like work and bookmark blurbs already do)

References

Same kind of fix as AO3-7356. for_blurb is also applied to series in bookmark search results, which get the same benefit.

Credit

Pablo Monfort (he/him)

This branch has not been deployed

No deployments
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.

1 participant