avoid N+1 query even if no custom fields exist

This commit is contained in:
Sam 2015-05-04 16:11:45 +10:00
parent 0369f26a39
commit 539ca73668
1 changed files with 6 additions and 2 deletions

View File

@ -292,8 +292,12 @@ class PostSerializer < BasicPostSerializer
end
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 ||= object.custom_fields
@post_custom_fields ||=
if @topic_view
@topic_view.post_custom_fields && @topic_view.post_custom_fields[object.id]
else
object.custom_fields
end
end
end