PERF: don't publish notification state unless it changed

This commit is contained in:
Sam Saffron 2016-01-06 10:22:03 +11:00
parent eaab27325d
commit 9f4efed03a

View File

@ -35,8 +35,14 @@ class Notification < ActiveRecord::Base
end
def self.mark_posts_read(user, topic_id, post_numbers)
Notification.where(user_id: user.id, topic_id: topic_id, post_number: post_numbers, read: false).update_all "read = 't'"
user.publish_notifications_state
count = Notification
.where(user_id: user.id,
topic_id: topic_id,
post_number: post_numbers,
read: false)
.update_all("read = 't'")
user.publish_notifications_state if count > 0
end
def self.interesting_after(min_date)