Load related objects in query
Reduces query load in template
This commit is contained in:
parent
8f56ad9e99
commit
085d3270a3
|
@ -13,7 +13,20 @@ class Notifications(View):
|
||||||
|
|
||||||
def get(self, request, notification_type=None):
|
def get(self, request, notification_type=None):
|
||||||
"""people are interacting with you, get hyped"""
|
"""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":
|
if notification_type == "mentions":
|
||||||
notifications = notifications.filter(
|
notifications = notifications.filter(
|
||||||
notification_type__in=["REPLY", "MENTION", "TAG"]
|
notification_type__in=["REPLY", "MENTION", "TAG"]
|
||||||
|
|
Loading…
Reference in New Issue