Use faster serializers for Search::Postgres::Tag (#13022)
* Use faster serializers for Search::Postgres::Tag * Fix spec
This commit is contained in:
parent
f222497913
commit
8b9f2d546c
2 changed files with 10 additions and 9 deletions
|
|
@ -4,13 +4,14 @@ module Search
|
|||
ATTRIBUTES = %i[id name hotness_score rules_html supported short_summary].freeze
|
||||
|
||||
def self.search_documents(term)
|
||||
::Tag
|
||||
.search_by_name(term)
|
||||
.where(supported: true)
|
||||
.reorder(hotness_score: :desc)
|
||||
.select(*ATTRIBUTES)
|
||||
.as_json
|
||||
results = ::Tag.search_by_name(term).where(supported: true).reorder(hotness_score: :desc).select(*ATTRIBUTES)
|
||||
serialize(results)
|
||||
end
|
||||
|
||||
def self.serialize(results)
|
||||
Search::TagSerializer.new(results, is_collection: true).serializable_hash[:data].pluck(:attributes)
|
||||
end
|
||||
private_class_method :serialize
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ RSpec.describe Search::Postgres::Tag, type: :service do
|
|||
result = described_class.search_documents(tag.name)
|
||||
|
||||
expect(result.first.keys).to match_array(
|
||||
%w[id name hotness_score rules_html supported short_summary],
|
||||
%i[id name hotness_score rules_html supported short_summary],
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ RSpec.describe Search::Postgres::Tag, type: :service do
|
|||
ruby = create(:tag, name: "ruby")
|
||||
|
||||
result = described_class.search_documents("jav")
|
||||
tags = result.map { |r| r["name"] }
|
||||
tags = result.pluck(:name)
|
||||
|
||||
expect(tags).to include(java.name)
|
||||
expect(tags).to include(javascript.name)
|
||||
|
|
@ -56,7 +56,7 @@ RSpec.describe Search::Postgres::Tag, type: :service do
|
|||
tag2.save!
|
||||
|
||||
result = described_class.search_documents("jav")
|
||||
tags = result.map { |r| r["name"] }
|
||||
tags = result.pluck(:name)
|
||||
|
||||
expect(tags).to eq([tag2.name, tag1.name])
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue