diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index 4ca9a3a2095..b2ef7441428 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -304,6 +304,7 @@ class TopicTrackingState topic_id: topic_id, min_new_topic_date: Time.at(SiteSetting.min_new_topics_time).to_datetime, max_topics: TopicTrackingState::MAX_TOPICS, + user_first_unread_at: user.user_stat.first_unread_at, }.merge(treat_as_new_topic_params), ) @@ -382,7 +383,7 @@ class TopicTrackingState filter_old_unread_sql = if filter_old_unread - " topics.updated_at >= us.first_unread_at AND " + " topics.updated_at >= :user_first_unread_at AND " else "" end @@ -413,7 +414,6 @@ class TopicTrackingState c.id as category_id, #{category_topic_id_column_select} tu.notification_level, - us.first_unread_at, GREATEST( CASE WHEN COALESCE(uo.new_topic_duration_minutes, :default_duration) = :always THEN u.created_at @@ -475,7 +475,6 @@ class TopicTrackingState SELECT #{select_sql} FROM topics JOIN users u on u.id = :user_id - JOIN user_stats AS us ON us.user_id = u.id JOIN user_options AS uo ON uo.user_id = u.id JOIN categories c ON c.id = topics.category_id LEFT JOIN topic_users tu ON tu.topic_id = topics.id AND tu.user_id = u.id