mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Make TopicViewSerializer#requested_group_name more efficient. (#14196)
* Avoid executing a query when the custom field doesn't exist * Avoid generating an ActiveRecord when all we need is the name.
This commit is contained in:
committed by
GitHub
parent
7a604215e0
commit
c2f87e0a36
@@ -484,4 +484,26 @@ describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#requested_group_name' do
|
||||
fab!(:pm) { Fabricate(:private_message_post).topic }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
|
||||
it 'should return the right group name when PM is a group membership request' do
|
||||
pm.custom_fields[:requested_group_id] = group.id
|
||||
pm.save!
|
||||
|
||||
user = pm.first_post.user
|
||||
group.add_owner(user)
|
||||
json = serialize_topic(pm, user)
|
||||
|
||||
expect(json[:requested_group_name]).to eq(group.name)
|
||||
end
|
||||
|
||||
it 'should not include the attribute for a non group membership request PM' do
|
||||
json = serialize_topic(pm, pm.first_post.user)
|
||||
|
||||
expect(json[:requested_group_name]).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user