mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
PERF: Keep track of first unread PM and first unread group PM for user.
This optimization helps to filter away topics so that the joins on related tables when querying for unread messages is not expensive.
This commit is contained in:

committed by
Alan Guo Xiang Tan

parent
0398271f87
commit
9b75d95fc6
@ -184,4 +184,41 @@ describe PostTiming do
|
||||
expect(post.reload.reads).to eq initial_read_count
|
||||
end
|
||||
end
|
||||
|
||||
describe '.destroy_last_for' do
|
||||
it 'updates first unread for a user correctly when topic is public' do
|
||||
post = Fabricate(:post)
|
||||
post.topic.update!(updated_at: 10.minutes.ago)
|
||||
PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])
|
||||
|
||||
PostTiming.destroy_last_for(post.user, post.topic_id)
|
||||
|
||||
expect(post.user.user_stat.reload.first_unread_at).to eq_time(post.topic.updated_at)
|
||||
end
|
||||
|
||||
it 'updates first unread for a user correctly when topic is a pm' do
|
||||
post = Fabricate(:private_message_post)
|
||||
post.topic.update!(updated_at: 10.minutes.ago)
|
||||
PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])
|
||||
|
||||
PostTiming.destroy_last_for(post.user, post.topic_id)
|
||||
|
||||
expect(post.user.user_stat.reload.first_unread_pm_at).to eq_time(post.topic.updated_at)
|
||||
end
|
||||
|
||||
it 'updates first unread for a user correctly when topic is a group pm' do
|
||||
topic = Fabricate(:private_message_topic, updated_at: 10.minutes.ago)
|
||||
post = Fabricate(:post, topic: topic)
|
||||
user = Fabricate(:user)
|
||||
group = Fabricate(:group)
|
||||
group.add(user)
|
||||
topic.allowed_groups << group
|
||||
PostTiming.process_timings(user, topic.id, 1, [[post.post_number, 100]])
|
||||
|
||||
PostTiming.destroy_last_for(user, topic.id)
|
||||
|
||||
expect(GroupUser.find_by(user: user, group: group).first_unread_pm_at)
|
||||
.to eq_time(post.topic.updated_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user