It's amazing what a little select_related can do

This commit is contained in:
Andrew Godwin 2022-12-20 15:35:48 +00:00
parent f82b82502c
commit 6039cde49e
2 changed files with 28 additions and 6 deletions

View file

@ -27,8 +27,18 @@ class Home(TemplateView):
identity=self.request.identity,
type__in=[TimelineEvent.Types.post, TimelineEvent.Types.boost],
)
.select_related("subject_post", "subject_post__author")
.prefetch_related("subject_post__attachments", "subject_post__mentions")
.select_related(
"subject_post",
"subject_post__author",
"subject_post__author__domain",
"subject_identity",
"subject_identity__domain",
)
.prefetch_related(
"subject_post__attachments",
"subject_post__mentions",
"subject_post__emojis",
)
.order_by("-published")
)
paginator = Paginator(events, 50)
@ -71,7 +81,7 @@ class Tag(ListView):
Post.objects.public()
.filter(author__restriction=Identity.Restriction.none)
.tagged_with(self.hashtag)
.select_related("author")
.select_related("author", "author__domain")
.prefetch_related("attachments", "mentions")
.order_by("-published")
)
@ -182,8 +192,13 @@ class Notifications(ListView):
"subject_post__author",
"subject_post__author__domain",
"subject_identity",
"subject_identity__domain",
)
.prefetch_related(
"subject_post__emojis",
"subject_post__mentions",
"subject_post__attachments",
)
.prefetch_related("subject_post__emojis")
)
def get_context_data(self, **kwargs):

View file

@ -21,8 +21,15 @@ def home(
identity=request.identity,
type__in=[TimelineEvent.Types.post],
)
.select_related("subject_post", "subject_post__author")
.prefetch_related("subject_post__attachments")
.select_related(
"subject_post",
"subject_post__author",
"subject_post__author__domain",
)
.prefetch_related(
"subject_post__attachments",
"subject_post__mentions",
)
.order_by("-published")
)
events = paginator.paginate(