Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PERF: Reduce size of search payload by removing unused topic attributes.
- Loading branch information
Showing
2 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
spec/serializers/search_topic_list_item_serializer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
84de643
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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