Load related objects in query

Reduces query load in template
This commit is contained in:
Mouse Reeve 2021-10-02 10:10:25 -07:00
parent 8f56ad9e99
commit 085d3270a3

View file

@ -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"]