Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

add simple eager loading to the notifications api

ulferts632f4f15c209
diff --git a/lib/api/v3/notifications/notification_representer.rb b/lib/api/v3/notifications/notification_representer.rb
index 24afbc5bd44..9c3ee2fe596 100644
--- a/lib/api/v3/notifications/notification_representer.rb
+++ b/lib/api/v3/notifications/notification_representer.rb
@@ -100,6 +100,10 @@ module API
'Notification'
end
+ self.to_eager_load = [:project,
+ :actor,
+ { journal: %i[attachable_journals customizable_journals] }]
+
##
# For notifications, we want to skip the initial journal
# as the information is not that useful
diff --git a/lib/api/v3/notifications/notifications_api.rb b/lib/api/v3/notifications/notifications_api.rb
index fb264f0790f..84922f5e94e 100644
--- a/lib/api/v3/notifications/notifications_api.rb
+++ b/lib/api/v3/notifications/notifications_api.rb
@@ -45,7 +45,9 @@ module API
def notification_scope
::Notification
.recipient(current_user)
- .where.not(reason_ian: nil)
+ .includes(NotificationRepresenter.to_eager_load)
+ .where
+ .not(reason_ian: nil)
end
def bulk_update_status(attributes)