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 query when rendering with StatusSerializer #15641

Merged
merged 1 commit into from
Jan 31, 2021

Conversation

abcang
Copy link
Contributor

@abcang abcang commented Jan 30, 2021

Since StatusSerializer is running user_shows_application?, it is running account.user internally. But until now, N+1 queries were occurring because user wasn't preloading.

https://github.com/tootsuite/mastodon/blob/13d5b8157904b2eb6b7f43e3fb834fca2f38f0dd/app/serializers/rest/status_serializer.rb#L47

@Gargron
Copy link
Member

Gargron commented Jan 30, 2021

User is loaded only to call setting which is a separate redis-cached model. So wasteful...

Perhaps it would be better to rewrite object.account.user_shows_application? to call the right setting directly?

@abcang
Copy link
Contributor Author

abcang commented Jan 30, 2021

I also thought it would be better to get the settings directly without going through user.
But I didn't come up with an idea for that concrete implementation.

@Gargron Gargron merged commit c8c764d into mastodon:main Jan 31, 2021
@abcang abcang deleted the fix_n_plus_1_in_status branch February 1, 2021 00:58
ClearlyClaire pushed a commit to ClearlyClaire/mastodon that referenced this pull request Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants