From 7116350bf8247e8d9eef2bc830bf7ac361ecdfc5 Mon Sep 17 00:00:00 2001 From: Kabiru Mwenja Date: Mon, 16 Dec 2024 21:11:39 +0300 Subject: [PATCH] [#60018] Ensure reminders are included in notifications eager loading wrapper https://community.openproject.org/work_packages/60018 --- .../notification_eager_loading_wrapper.rb | 17 ----------------- .../notifications/notification_representer.rb | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/lib/api/v3/notifications/notification_eager_loading_wrapper.rb b/lib/api/v3/notifications/notification_eager_loading_wrapper.rb index 55ce073a95c2..509e5776b7fb 100644 --- a/lib/api/v3/notifications/notification_eager_loading_wrapper.rb +++ b/lib/api/v3/notifications/notification_eager_loading_wrapper.rb @@ -35,23 +35,6 @@ def wrap(notifications) notifications .includes(API::V3::Notifications::NotificationRepresenter.to_eager_load) .to_a - .tap { |loaded_notifications| set_resource(loaded_notifications) } - end - - private - - # The resource cannot be loaded by rails eager loading means (include) - # because it is a polymorphic association. That being as it is, currently only - # work packages are assigned. - def set_resource(notifications) - work_packages_by_id = WorkPackage - .includes(:project) - .where(id: notifications.pluck(:resource_id).uniq) - .index_by(&:id) - - notifications.each do |notification| - notification.resource = work_packages_by_id[notification.resource_id] - end end end end diff --git a/lib/api/v3/notifications/notification_representer.rb b/lib/api/v3/notifications/notification_representer.rb index 6984fe235187..dfc90493b3ca 100644 --- a/lib/api/v3/notifications/notification_representer.rb +++ b/lib/api/v3/notifications/notification_representer.rb @@ -104,7 +104,7 @@ def _type "Notification" end - self.to_eager_load = %i[actor journal reminder] + self.to_eager_load = [:actor, :journal, :reminder, { resource: :project }] end end end