AO3-4412 Adding a test to ensure there are not N+1 issues when loading inbox comments on the homepage#5913
Conversation
…g inbox commets on the homepage
| # 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. |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
| 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) ?
Pull Request Checklist
as the first thing in your pull request title (e.g.
AO3-1234 Fix thing)until they are reviewed and merged before creating new pull requests.
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