mirror of
https://github.com/jointakahe/takahe.git
synced 2025-02-19 17:06:16 +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.utils.decorators import method_decorator
|
||||||
from django.views.generic import ListView
|
from django.views.generic import ListView
|
||||||
|
|
||||||
|
@ -23,15 +24,23 @@ class Follows(ListView):
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
if self.inbound:
|
if self.inbound:
|
||||||
return Follow.objects.filter(
|
follow_dir = models.Q(target=self.request.identity)
|
||||||
target=self.request.identity,
|
|
||||||
state__in=FollowStates.group_active(),
|
|
||||||
).order_by("-created")
|
|
||||||
else:
|
else:
|
||||||
return Follow.objects.filter(
|
follow_dir = models.Q(source=self.request.identity)
|
||||||
source=self.request.identity,
|
|
||||||
|
return (
|
||||||
|
Follow.objects.filter(
|
||||||
|
follow_dir,
|
||||||
state__in=FollowStates.group_active(),
|
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):
|
def follows_to_identities(self, follows, attr):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -33,6 +33,9 @@ class Home(TemplateView):
|
||||||
"subject_post__author__domain",
|
"subject_post__author__domain",
|
||||||
"subject_identity",
|
"subject_identity",
|
||||||
"subject_identity__domain",
|
"subject_identity__domain",
|
||||||
|
"subject_post_interaction",
|
||||||
|
"subject_post_interaction__identity",
|
||||||
|
"subject_post_interaction__identity__domain",
|
||||||
)
|
)
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
"subject_post__attachments",
|
"subject_post__attachments",
|
||||||
|
@ -193,6 +196,9 @@ class Notifications(ListView):
|
||||||
"subject_post__author__domain",
|
"subject_post__author__domain",
|
||||||
"subject_identity",
|
"subject_identity",
|
||||||
"subject_identity__domain",
|
"subject_identity__domain",
|
||||||
|
"subject_post_interaction",
|
||||||
|
"subject_post_interaction__identity",
|
||||||
|
"subject_post_interaction__identity__domain",
|
||||||
)
|
)
|
||||||
.prefetch_related(
|
.prefetch_related(
|
||||||
"subject_post__emojis",
|
"subject_post__emojis",
|
||||||
|
|
Loading…
Reference in a new issue