Skip to content

AO3-4412 Adding a test to ensure there are not N+1 issues when loading inbox comments on the homepage#5913

Open
ASalbenblatt wants to merge 2 commits into
otwcode:masterfrom
ASalbenblatt:AO3-4412-N+1-on-logged-in-homepage-for-inbox
Open

AO3-4412 Adding a test to ensure there are not N+1 issues when loading inbox comments on the homepage#5913
ASalbenblatt wants to merge 2 commits into
otwcode:masterfrom
ASalbenblatt:AO3-4412-N+1-on-logged-in-homepage-for-inbox

Conversation

@ASalbenblatt

@ASalbenblatt ASalbenblatt commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Issue

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

Purpose

There used to be an issue where there were N+1 database queries when loading inbox comments on the homepage. It looks like this was fixed in AO3-4380, though a test was never added. This PR adds a test for that fix so it won't happen again.

Testing Instructions

Testing is all automated.

Note: the line numbers in the Jira issue no longer point to the relevant lines, as they have moved from commits in the intervening years.

Credit

FlyingFalcon they/them

@github-actions github-actions Bot added Scope: Tests Only Only changes automated tests or test configuration Awaiting Review labels Jun 28, 2026
Comment on lines +40 to +42
# we're checking for here. But we also don't want to put too much
# unnecessary load on the databases when we have a bunch of cache hits,
# so this requires some care & tuning.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While this is the case for work blurbs, it's not the case for homepage inbox comments which aren't cached like work blurbs are. There are still a number of N+1 queries that can be avoided here and that we'd indeed like to avoid. You can refer to the very similar case of #5890 for some pointers of what queries to avoid (e.g. the role queries also show up in my logs for the homepage) and what kind of variants would be good to cover in the test


context "when all works are cached" do
populate do |n|
create_list(:inbox_comment, n)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
create_list(:inbox_comment, n)
create_list(:inbox_comment, n, user: user)

also for the other create_list, otherwise this doesn't have any comments on the homepage for the user

To make sure the test fails in the future when it's not displaying more than one comment, could you add an expect for the number of comments after the subject.call, similar to how it's done in the work tests with expect(response.body.scan('<li id="work_').size).to eq(current_scale.to_i) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed: Action Needed Scope: Tests Only Only changes automated tests or test configuration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants