From 590149fd48d87203ac2e164cc6c3ec6baf957b34 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Tue, 10 Sep 2019 11:27:23 -0400 Subject: [PATCH] Fix notifications past aggregation query (#3998) --- app/controllers/notifications_controller.rb | 2 +- app/models/notification.rb | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index f82deeefc..6ca654c16 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -26,7 +26,7 @@ class NotificationsController < ApplicationController @user.notifications end - @notifications = @notifications.without_recently_aggregated_reactions_and_follows.order(notified_at: :desc) + @notifications = @notifications.without_past_aggregations.order(notified_at: :desc) # if offset based pagination is invoked by the frontend code, we filter out all earlier ones @notifications = @notifications.where("notified_at < ?", notified_at_offset) if notified_at_offset diff --git a/app/models/notification.rb b/app/models/notification.rb index b0f2c5aae..82dc93937 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -22,12 +22,8 @@ class Notification < ApplicationRecord where(organization_id: org_id, notifiable_type: "Mention", user_id: nil) } - scope :with_recently_aggregated_reactions_and_follows, lambda { - where("notified_at < ?", 24.hours.ago). - where(action: %w[Reaction Follow]) - } - scope :without_recently_aggregated_reactions_and_follows, lambda { - where.not(with_recently_aggregated_reactions_and_follows.arel.exists) + scope :without_past_aggregations, lambda { + where.not("notified_at < ? AND action IN ('Reaction', 'Follow')", 24.hours.ago) } class << self