mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 06:52:46 +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
|
unread_posts(user, topic).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_notifications(user, type, topic)
|
def destroy_notifications(user, types, topic)
|
||||||
return if user.blank?
|
return if user.blank?
|
||||||
return unless Guardian.new(user).can_see?(topic)
|
return unless Guardian.new(user).can_see?(topic)
|
||||||
|
|
||||||
user.notifications.where(notification_type: type,
|
user.notifications.where(
|
||||||
topic_id: topic.id).destroy_all
|
notification_type: types,
|
||||||
|
topic_id: topic.id
|
||||||
|
).destroy_all
|
||||||
|
|
||||||
# HACK so notification counts sync up correctly
|
# HACK so notification counts sync up correctly
|
||||||
user.reload
|
user.reload
|
||||||
end
|
end
|
||||||
|
@ -326,9 +329,7 @@ class PostAlerter
|
||||||
collapsed = false
|
collapsed = false
|
||||||
|
|
||||||
if COLLAPSED_NOTIFICATION_TYPES.include?(type)
|
if COLLAPSED_NOTIFICATION_TYPES.include?(type)
|
||||||
COLLAPSED_NOTIFICATION_TYPES.each do |t|
|
destroy_notifications(user, COLLAPSED_NOTIFICATION_TYPES, post.topic)
|
||||||
destroy_notifications(user, t, post.topic)
|
|
||||||
end
|
|
||||||
collapsed = true
|
collapsed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -267,8 +267,15 @@ describe PostAlerter do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'notifies a user by username' do
|
it 'notifies a user by username' do
|
||||||
|
topic = Fabricate(:topic)
|
||||||
|
|
||||||
expect {
|
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)
|
}.to change(evil_trout.notifications, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user