mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 02:32:45 +08:00
PERF: Destroy collapsed notifications in 1 query instead of 3.
This commit is contained in:
parent
80adc1ee80
commit
755b511b5c
|
@ -174,12 +174,15 @@ class PostAlerter
|
|||
unread_posts(user, topic).count
|
||||
end
|
||||
|
||||
def destroy_notifications(user, type, topic)
|
||||
def destroy_notifications(user, types, topic)
|
||||
return if user.blank?
|
||||
return unless Guardian.new(user).can_see?(topic)
|
||||
|
||||
user.notifications.where(notification_type: type,
|
||||
topic_id: topic.id).destroy_all
|
||||
user.notifications.where(
|
||||
notification_type: types,
|
||||
topic_id: topic.id
|
||||
).destroy_all
|
||||
|
||||
# HACK so notification counts sync up correctly
|
||||
user.reload
|
||||
end
|
||||
|
@ -326,9 +329,7 @@ class PostAlerter
|
|||
collapsed = false
|
||||
|
||||
if COLLAPSED_NOTIFICATION_TYPES.include?(type)
|
||||
COLLAPSED_NOTIFICATION_TYPES.each do |t|
|
||||
destroy_notifications(user, t, post.topic)
|
||||
end
|
||||
destroy_notifications(user, COLLAPSED_NOTIFICATION_TYPES, post.topic)
|
||||
collapsed = true
|
||||
end
|
||||
|
||||
|
|
|
@ -267,8 +267,15 @@ describe PostAlerter do
|
|||
end
|
||||
|
||||
it 'notifies a user by username' do
|
||||
topic = Fabricate(:topic)
|
||||
|
||||
expect {
|
||||
create_post_with_alerts(raw: '[quote="EvilTrout, post:1"]whatup[/quote]')
|
||||
2.times do
|
||||
create_post_with_alerts(
|
||||
raw: '[quote="EvilTrout, post:1"]whatup[/quote]',
|
||||
topic: topic
|
||||
)
|
||||
end
|
||||
}.to change(evil_trout.notifications, :count).by(1)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user