PERF: creating a post would cause an N+1 (#21768)

In the case where the `@topic_view` is not present we were fetching users without including `:user_status`, which would cause an N+1
This commit is contained in:
Joffrey JAFFEUX 2023-05-26 17:12:46 +02:00 committed by GitHub
parent 2a748ff5cb
commit a6a5c1b69b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -570,7 +570,9 @@ class PostSerializer < BasicPostSerializer
if @topic_view && (mentioned_users = @topic_view.mentioned_users[object.id])
mentioned_users
else
User.where(username: object.mentions)
query = User
query = query.includes(:user_status) if SiteSetting.enable_user_status
query = query.where(username: object.mentions)
end
users.map { |user| BasicUserWithStatusSerializer.new(user, root: false) }