From 085d3270a328102d20d21ffe755c96b0042b05f1 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 2 Oct 2021 10:10:25 -0700 Subject: [PATCH] Load related objects in query Reduces query load in template --- bookwyrm/views/notifications.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bookwyrm/views/notifications.py b/bookwyrm/views/notifications.py index 0c82f541..0a7a6200 100644 --- a/bookwyrm/views/notifications.py +++ b/bookwyrm/views/notifications.py @@ -13,7 +13,20 @@ class Notifications(View): def get(self, request, notification_type=None): """people are interacting with you, get hyped""" - notifications = request.user.notification_set.all().order_by("-created_date") + notifications = ( + request.user.notification_set.all() + .order_by("-created_date") + .select_related( + "related_status", + "related_status__reply_parent", + "related_import", + "related_report", + "related_user", + "related_book", + "related_list_item", + "related_list_item__book", + ) + ) if notification_type == "mentions": notifications = notifications.filter( notification_type__in=["REPLY", "MENTION", "TAG"]