From 539ca736680935318e4e7b052da75bf4fc8afff8 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 4 May 2015 16:11:45 +1000 Subject: [PATCH] avoid N+1 query even if no custom fields exist --- app/serializers/post_serializer.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index 59f557799d..c8262adabf 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -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