From 40f7f8f525b67c5ffc7ebb9478736f08970b606a Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 2 Feb 2023 11:03:27 +0100 Subject: [PATCH] Eager load notification targets --- app/models/notification.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 0bf19ff7..60890d17 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -11,11 +11,11 @@ class Notification < ApplicationRecord define_cursor_paginator :cursored_for_type, :for_type def for(recipient, **kwargs) - where(kwargs.merge!(recipient:)).order(:created_at).reverse_order + where(kwargs.merge!(recipient:)).includes(:target).order(:created_at).reverse_order end def for_type(recipient, type, **kwargs) - where(kwargs.merge!(recipient:)).where(type:).order(:created_at).reverse_order + where(kwargs.merge!(recipient:)).includes(:target).where(type:).order(:created_at).reverse_order end def notify(recipient, target)