mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-13 02:41:08 +00:00
Optimize timeline queries (#219)
This commit is contained in:
parent
fa4ee7e32f
commit
a7082decc8
2 changed files with 22 additions and 7 deletions
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue