From 10a6824e5f49a69c43bf6cb3f09de0a1c57bb0d4 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 23 Jul 2020 09:25:31 +0800 Subject: [PATCH] Revert "PERF: Reduce size of search payload by removing unused topic attributes." This reverts commit 84de643c04bf83740ccf9f085e0ff441d9482651. Users are using the search endpoint as public API even though it is meant to be internal. Revert for now while we figure out the path forward on providing a more stable API to end users. --- .../search_topic_list_item_serializer.rb | 21 +++------- .../search_topic_list_item_serializer_spec.rb | 42 ------------------- 2 files changed, 6 insertions(+), 57 deletions(-) delete mode 100644 spec/serializers/search_topic_list_item_serializer_spec.rb diff --git a/app/serializers/search_topic_list_item_serializer.rb b/app/serializers/search_topic_list_item_serializer.rb index b53f67a1001..2dd83d8da78 100644 --- a/app/serializers/search_topic_list_item_serializer.rb +++ b/app/serializers/search_topic_list_item_serializer.rb @@ -5,20 +5,11 @@ class SearchTopicListItemSerializer < ListableTopicSerializer attributes :category_id - %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 + def include_image_url? + false + end + + def include_thumbnails? + false end end diff --git a/spec/serializers/search_topic_list_item_serializer_spec.rb b/spec/serializers/search_topic_list_item_serializer_spec.rb deleted file mode 100644 index 639d1ff73c4..00000000000 --- a/spec/serializers/search_topic_list_item_serializer_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# 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