mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-25 08:41:00 +00:00
Prevent n+1 queries when rendering timelines (#165)
The linkify_mentions function is traversing the post's mentions, so better prefetch those.
This commit is contained in:
parent
d1ce056288
commit
8db05bed95
1 changed files with 4 additions and 4 deletions
|
@ -25,7 +25,7 @@ class Home(FormView):
|
||||||
type__in=[TimelineEvent.Types.post, TimelineEvent.Types.boost],
|
type__in=[TimelineEvent.Types.post, TimelineEvent.Types.boost],
|
||||||
)
|
)
|
||||||
.select_related("subject_post", "subject_post__author")
|
.select_related("subject_post", "subject_post__author")
|
||||||
.prefetch_related("subject_post__attachments")
|
.prefetch_related("subject_post__attachments", "subject_post__mentions")
|
||||||
.order_by("-created")[:50]
|
.order_by("-created")[:50]
|
||||||
)
|
)
|
||||||
context["interactions"] = PostInteraction.get_event_interactions(
|
context["interactions"] = PostInteraction.get_event_interactions(
|
||||||
|
@ -70,7 +70,7 @@ class Tag(ListView):
|
||||||
Post.objects.public()
|
Post.objects.public()
|
||||||
.tagged_with(self.hashtag)
|
.tagged_with(self.hashtag)
|
||||||
.select_related("author")
|
.select_related("author")
|
||||||
.prefetch_related("attachments")
|
.prefetch_related("attachments", "mentions")
|
||||||
.order_by("-created")[:50]
|
.order_by("-created")[:50]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class Local(ListView):
|
||||||
return (
|
return (
|
||||||
Post.objects.local_public()
|
Post.objects.local_public()
|
||||||
.select_related("author")
|
.select_related("author")
|
||||||
.prefetch_related("attachments")
|
.prefetch_related("attachments", "mentions")
|
||||||
.order_by("-created")[:50]
|
.order_by("-created")[:50]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ class Federated(ListView):
|
||||||
visibility=Post.Visibilities.public, in_reply_to__isnull=True
|
visibility=Post.Visibilities.public, in_reply_to__isnull=True
|
||||||
)
|
)
|
||||||
.select_related("author")
|
.select_related("author")
|
||||||
.prefetch_related("attachments")
|
.prefetch_related("attachments", "mentions")
|
||||||
.order_by("-created")[:50]
|
.order_by("-created")[:50]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue