From 7d59ff67b8a8f4c653241000ba0f69b42f2732e2 Mon Sep 17 00:00:00 2001 From: Sam Saffron <sam.saffron@gmail.com> Date: Thu, 25 May 2017 18:40:32 -0400 Subject: [PATCH] adjust qurey to include messages, once everything is read then mark first_topic_unread_at to be current time --- app/models/user_stat.rb | 4 ++-- db/migrate/20170524182846_add_unread_tracking_columns.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/user_stat.rb b/app/models/user_stat.rb index c2678cc905a..3416f3233c3 100644 --- a/app/models/user_stat.rb +++ b/app/models/user_stat.rb @@ -85,7 +85,7 @@ class UserStat < ActiveRecord::Base exec_sql <<SQL UPDATE user_stats us - SET first_topic_unread_at = COALESCE(X.first_unread_at, 'epoch') + SET first_topic_unread_at = COALESCE(X.first_unread_at, current_timestamp) FROM ( SELECT u.id user_id, MIN(last_unread_at) first_unread_at @@ -96,7 +96,7 @@ class UserStat < ActiveRecord::Base THEN t.highest_staff_post_number ELSE t.highest_post_number END - AND t.deleted_at IS NULL AND t.archetype <> 'private_message' + AND t.deleted_at IS NULL GROUP BY u.id ) X WHERE X.user_id = us.user_id AND X.first_unread_at <> first_topic_unread_at diff --git a/db/migrate/20170524182846_add_unread_tracking_columns.rb b/db/migrate/20170524182846_add_unread_tracking_columns.rb index 9235c49dbb1..e8cf14ca58b 100644 --- a/db/migrate/20170524182846_add_unread_tracking_columns.rb +++ b/db/migrate/20170524182846_add_unread_tracking_columns.rb @@ -20,8 +20,8 @@ SQL THEN topics.highest_staff_post_number ELSE topics.highest_post_number END - AND topics.deleted_at IS NULL AND topics.archetype <> 'private_message' - ), 'epoch') + AND topics.deleted_at IS NULL + ), current_timestamp) SQL add_index :topics, [:last_unread_at]