From 9f4efed03aadce60a7d7ddd3dcde74603aa73630 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 6 Jan 2016 10:22:03 +1100 Subject: [PATCH] PERF: don't publish notification state unless it changed --- app/models/notification.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index f9611d2a6c0..303025b2d4e 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -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)