From 0dc09f32463854145ff3d4cafd1845e9e3313ff1 Mon Sep 17 00:00:00 2001 From: sumingxuan <1154621382@qq.com> Date: Tue, 23 Mar 2021 18:51:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=96=87=E4=BB=B6=EF=BC=8C=E5=B9=B6=E4=B8=94?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notifications/notifications_controller.rb | 2 +- lib/notifications/base.rb | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 lib/notifications/base.rb diff --git a/app/controllers/notifications/notifications_controller.rb b/app/controllers/notifications/notifications_controller.rb index 550e616..d491975 100644 --- a/app/controllers/notifications/notifications_controller.rb +++ b/app/controllers/notifications/notifications_controller.rb @@ -3,7 +3,7 @@ class NotificationsController < Notifications::ApplicationController def index @notifications = notifications.includes(:actor).order("id desc").page(params[:page]) - unread_ids = @notifications.reject(&:read?).select(&:id) + unread_ids = @notifications.unread.ids Notification.read!(current_user, unread_ids) @notification_groups = @notifications.group_by { |note| note.created_at.to_date } diff --git a/lib/notifications/base.rb b/lib/notifications/base.rb deleted file mode 100644 index f155838..0000000 --- a/lib/notifications/base.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Notifications - class Base - extend ActiveSupport::Concern - - included do - end - - class_methods do - def - end - end -end From 885ca1083d7e41966654a1a8301ef251edf7a6ac Mon Sep 17 00:00:00 2001 From: sumingxuan <1154621382@qq.com> Date: Tue, 23 Mar 2021 22:21:30 +0800 Subject: [PATCH 2/2] notification_groups use lazy loading relation --- app/controllers/notifications/notifications_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/notifications/notifications_controller.rb b/app/controllers/notifications/notifications_controller.rb index d491975..a067b38 100644 --- a/app/controllers/notifications/notifications_controller.rb +++ b/app/controllers/notifications/notifications_controller.rb @@ -2,11 +2,10 @@ module Notifications class NotificationsController < Notifications::ApplicationController def index @notifications = notifications.includes(:actor).order("id desc").page(params[:page]) + @notification_groups = @notifications.group_by { |note| note.created_at.to_date } unread_ids = @notifications.unread.ids Notification.read!(current_user, unread_ids) - - @notification_groups = @notifications.group_by { |note| note.created_at.to_date } end def read