PERF: Reduce size of search payload by removing unused topic attributes.

PERF: Reduce size of search payload by removing unused topic attributes.

diff --git a/app/serializers/search_topic_list_item_serializer.rb b/app/serializers/search_topic_list_item_serializer.rb
index 2dd83d8..b53f67a 100644
--- a/app/serializers/search_topic_list_item_serializer.rb
+++ b/app/serializers/search_topic_list_item_serializer.rb
@@ -5,11 +5,20 @@ class SearchTopicListItemSerializer < ListableTopicSerializer
 
   attributes :category_id
 
-  def include_image_url?
-    false
-  end
-
-  def include_thumbnails?
-    false
+  %i{
+    image_url
+    thumbnails
+    title
+    created_at
+    last_posted_at
+    bumped_at
+    bumped
+    highest_post_number
+    reply_count
+    unseen
+  }.each do |attr|
+    define_method("include_#{attr}?") do
+      false
+    end
   end
 end
diff --git a/spec/serializers/search_topic_list_item_serializer_spec.rb b/spec/serializers/search_topic_list_item_serializer_spec.rb
new file mode 100644
index 0000000..639d1ff
--- /dev/null
+++ b/spec/serializers/search_topic_list_item_serializer_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe SearchTopicListItemSerializer do
+  fab!(:admin) { Fabricate(:admin) }
+  fab!(:post) { Fabricate(:post) }
+  let(:topic) { post.topic }
+
+  let(:serializer) do
+    SearchTopicListItemSerializer.new(topic, scope: Guardian.new(admin), root: false)
+  end
+
+  it 'should only include the required keys' do
+    current_keys = serializer.as_json.keys
+
+    expected_keys = [
+      :id,
+      :fancy_title,
+      :slug,
+      :posts_count,
+      :archetype,
+      :pinned,
+      :unpinned,
+      :visible,
+      :closed,
+      :archived,
+      :bookmarked,
+      :liked,
+      :category_id
+    ]
+
+    extra_keys = current_keys - expected_keys
+    missing_keys = expected_keys - current_keys
+
+    expect(extra_keys).to eq([]), lambda {
+      "Please verify if the following keys are required as part of the serializer's payload: #{extra_keys.join(", ")}"
+    }
+
+    expect(missing_keys).to eq([])
+  end
+end

GitHub sha: 84de643c

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/move-to-existing-topic-is-missing-title-of-suggested-topics/157974/5