Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix N+1 queries in NotificationsController #21202

Merged
merged 1 commit into from
Dec 15, 2022

Conversation

nametoolong
Copy link
Contributor

In #19319, the noindex attribute is added to AccountSerializer. The field is defined in the User model instead of the Account model, so an extra query will occur if the User model is not preloaded. The notifications controller returns the account associated with a notification, but does not preload from_account.user. Therefore, N+1 queries happen when rendering notifications.

This PR fixes the issue by preloading :user in NotificationsController#load_notifications.

@nametoolong nametoolong changed the title Fix N+1 queries from in NotificationsController Fix N+1 queries in NotificationsController Nov 20, 2022
Copy link
Contributor

@ClearlyClaire ClearlyClaire left a comment

Choose a reason for hiding this comment

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

Note that the setting is not stored directly in the users table so there might still be a N+1, but it is mitigated by Rails-level caching, and we may move the setting directly in the users table in the future.

Nonetheless, this is a welcome change!

Copy link

@xuanxu xuanxu left a comment

Choose a reason for hiding this comment

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

👍

@ineffyble ineffyble added the bug Something isn't working label Nov 24, 2022
@Gargron Gargron merged commit 63b379c into mastodon:main Dec 15, 2022
neatchee pushed a commit to neatchee/mastodon that referenced this pull request Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants