PERF: Exclude `image_url` and `thumbnails` from `SearchTopicListItemSerializer`.

PERF: Exclude image_url and thumbnails from SearchTopicListItemSerializer.

The attributes are not used and was resulting in N+1 queries.

diff --git a/app/serializers/search_topic_list_item_serializer.rb b/app/serializers/search_topic_list_item_serializer.rb
index faf1322..2dd83d8 100644
--- a/app/serializers/search_topic_list_item_serializer.rb
+++ b/app/serializers/search_topic_list_item_serializer.rb
@@ -4,4 +4,12 @@ class SearchTopicListItemSerializer < ListableTopicSerializer
   include TopicTagsMixin
 
   attributes :category_id
+
+  def include_image_url?
+    false
+  end
+
+  def include_thumbnails?
+    false
+  end
 end

GitHub sha: 01a72288

2 Likes

Interesting!

@davidtaylorhq is this a use case that you thought about in the past. mayyyyybe on a very image heavy site if you are searching in a category that has images enabled you would enable it.

Still … no N+1 is certainly the way to go now.

1 Like

Actually I’m in the midst of checking with @davidtaylorhq why the attributes are included by default when the default views of core do not need those attributes.

2 Likes

Usually we use theme modifiers here for this … so themes would opt in with the modifiers. Maybe we missed it.

1 Like

@davidtaylorhq Do you want to take a stab at removing thumbnails from the default payload and only enable it with theme_modifiers?

2 Likes

Sure, I’ll open a PR

Unconditionally including the thumbnails array was originally by design, but you’re right - it’s probably not worth the extra bytes in the payload since we don’t use it in core. I think we should keep image_url though, because lots of people already use it via the API.

1 Like