mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 10:33:51 +08:00
PERF: Remove redundant DB queries from TopicView
(#19658)
This commit removes 3 redundant DB queries when loading posts. 1. `@posts` will eventually have to be loaded so we can avoid two additional queries. 2. No need to preload topic association of posts as we're already dealing with a fixed topic in `TopicView`.
This commit is contained in:
parent
d8a19b2c9a
commit
be1ae9411b
|
@ -139,11 +139,11 @@ class TopicView
|
|||
|
||||
if @posts && !@skip_custom_fields
|
||||
if (added_fields = User.allowed_user_custom_fields(@guardian)).present?
|
||||
@user_custom_fields = User.custom_fields_for_ids(@posts.pluck(:user_id), added_fields)
|
||||
@user_custom_fields = User.custom_fields_for_ids(@posts.map(&:user_id), added_fields)
|
||||
end
|
||||
|
||||
if (allowed_fields = TopicView.allowed_post_custom_fields(@user, @topic)).present?
|
||||
@post_custom_fields = Post.custom_fields_for_ids(@posts.pluck(:id), allowed_fields)
|
||||
@post_custom_fields = Post.custom_fields_for_ids(@posts.map(&:id), allowed_fields)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -778,7 +778,6 @@ class TopicView
|
|||
:reply_to_user,
|
||||
:deleted_by,
|
||||
:incoming_email,
|
||||
:topic,
|
||||
:image_upload
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user