Optimize timeline queries (#219)

This commit is contained in:
Michael Manfre 2022-12-21 06:09:18 -05:00 committed by GitHub
parent fa4ee7e32f
commit a7082decc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View file

@ -1,3 +1,4 @@
from django.db import models
from django.utils.decorators import method_decorator
from django.views.generic import ListView
@ -23,15 +24,23 @@ class Follows(ListView):
def get_queryset(self):
if self.inbound:
return Follow.objects.filter(
target=self.request.identity,
state__in=FollowStates.group_active(),
).order_by("-created")
follow_dir = models.Q(target=self.request.identity)
else:
return Follow.objects.filter(
source=self.request.identity,
follow_dir = models.Q(source=self.request.identity)
return (
Follow.objects.filter(
follow_dir,
state__in=FollowStates.group_active(),
).order_by("-created")
)
.select_related(
"target",
"target__domain",
"source",
"source__domain",
)
.order_by("-created")
)
def follows_to_identities(self, follows, attr):
"""

View file

@ -33,6 +33,9 @@ class Home(TemplateView):
"subject_post__author__domain",
"subject_identity",
"subject_identity__domain",
"subject_post_interaction",
"subject_post_interaction__identity",
"subject_post_interaction__identity__domain",
)
.prefetch_related(
"subject_post__attachments",
@ -193,6 +196,9 @@ class Notifications(ListView):
"subject_post__author__domain",
"subject_identity",
"subject_identity__domain",
"subject_post_interaction",
"subject_post_interaction__identity",
"subject_post_interaction__identity__domain",
)
.prefetch_related(
"subject_post__emojis",