Skip to content

AO3-7457 Preload unrevealed collections for work blurbs#5907

Open
nateberkopec wants to merge 4 commits into
otwcode:masterfrom
nateberkopec:nb/preload-unrevealed-work-blurbs
Open

AO3-7457 Preload unrevealed collections for work blurbs#5907
nateberkopec wants to merge 4 commits into
otwcode:masterfrom
nateberkopec:nb/preload-unrevealed-work-blurbs

Conversation

@nateberkopec

@nateberkopec nateberkopec commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Issue

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

Purpose

This removes an N+1 when rendering mystery blurbs on many, many different pages.

Prior to this change, rendering a mystery blurb called:

item.approved_collections.unrevealed.present?

This is a guaranteed N+1, because scope calls on associations cannot be preloaded.

The fix here is to change that into a relation, approved_unrevealed_collections, which can be preloaded.

As a regression test/enforcement mechanism, we use strict_loading: true to ensure that exceptions are raised in dev/test if this new association is ever not preloaded. Once that exception was raised, all I had to do was backfill through all the controllers to add for_blurb preloads where missing and then the exceptions went away.

Because this adds for_blurb preloads in a number of places, it probably also removes additional N+1s from the non-mystery blurb as well.

This is part of (but does not close) AO3-7457 because it is cleaning up data access for this set of partials before adding fragment caching around it.

@nateberkopec nateberkopec changed the title Preload unrevealed collections for work blurbs [AO3-7457] Preload unrevealed collections for work blurbs Jun 23, 2026
@nateberkopec nateberkopec force-pushed the nb/preload-unrevealed-work-blurbs branch from 73fd150 to 9d22ce5 Compare June 23, 2026 22:14
Comment thread app/views/works/_mystery_blurb.html.erb Outdated
<% if item.approved_collections.unrevealed.present? %>
<h5 class="heading"><%= h(ts("Part of ")) + show_collections_data(item.approved_collections.unrevealed) %></h5>
<% if approved_unrevealed_collections.any? %>
<h5 class="heading"><%= h(t(".part_of", default: "Part of ")) + show_collections_data(item.approved_unrevealed_collections) %></h5>

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.

Change is unrelated but was enforced on me by Rubocop

@nateberkopec nateberkopec force-pushed the nb/preload-unrevealed-work-blurbs branch 4 times, most recently from 4755e28 to 0f54639 Compare June 23, 2026 23:34
@nateberkopec nateberkopec force-pushed the nb/preload-unrevealed-work-blurbs branch from 0f54639 to 19131f7 Compare June 23, 2026 23:39
@sarken sarken changed the title [AO3-7457] Preload unrevealed collections for work blurbs AO3-7457 Preload unrevealed collections for work blurbs Jun 24, 2026
@nateberkopec

Copy link
Copy Markdown
Contributor Author

Noticed some missing stuff re polymorphism.

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