mirror of
https://github.com/discourse/discourse.git
synced 2025-06-10 17:33:42 +08:00
avoid N+1 query even if no custom fields exist
This commit is contained in:
@ -292,8 +292,12 @@ class PostSerializer < BasicPostSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def post_custom_fields
|
def post_custom_fields
|
||||||
@post_custom_fields ||= (@topic_view.present? && @topic_view.post_custom_fields.present?) ? @topic_view.post_custom_fields[object.id] : nil
|
@post_custom_fields ||=
|
||||||
@post_custom_fields ||= object.custom_fields
|
if @topic_view
|
||||||
|
@topic_view.post_custom_fields && @topic_view.post_custom_fields[object.id]
|
||||||
|
else
|
||||||
|
object.custom_fields
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user