summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Rodríguez Alberich2022-12-14 18:16:22 +0100
committerGitHub2022-12-14 10:16:22 -0700
commit8db05bed9542f907dd9e1bcd4eac44a2a79467ff (patch)
tree398807603e0522dac99b87a69436004ecd09aa10
parentd1ce056288c97eea18e17f1b950194678618cefc (diff)
downloadtakahe-8db05bed9542f907dd9e1bcd4eac44a2a79467ff.tar.gz
takahe-8db05bed9542f907dd9e1bcd4eac44a2a79467ff.tar.bz2
takahe-8db05bed9542f907dd9e1bcd4eac44a2a79467ff.zip
Prevent n+1 queries when rendering timelines (#165)
The linkify_mentions function is traversing the post's mentions, so better prefetch those.
-rw-r--r--activities/views/timelines.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/activities/views/timelines.py b/activities/views/timelines.py
index a562520..0c1b693 100644
--- a/activities/views/timelines.py
+++ b/activities/views/timelines.py
@@ -25,7 +25,7 @@ class Home(FormView):
type__in=[TimelineEvent.Types.post, TimelineEvent.Types.boost],
)
.select_related("subject_post", "subject_post__author")
- .prefetch_related("subject_post__attachments")
+ .prefetch_related("subject_post__attachments", "subject_post__mentions")
.order_by("-created")[:50]
)
context["interactions"] = PostInteraction.get_event_interactions(
@@ -70,7 +70,7 @@ class Tag(ListView):
Post.objects.public()
.tagged_with(self.hashtag)
.select_related("author")
- .prefetch_related("attachments")
+ .prefetch_related("attachments", "mentions")
.order_by("-created")[:50]
)
@@ -99,7 +99,7 @@ class Local(ListView):
return (
Post.objects.local_public()
.select_related("author")
- .prefetch_related("attachments")
+ .prefetch_related("attachments", "mentions")
.order_by("-created")[:50]
)
@@ -127,7 +127,7 @@ class Federated(ListView):
visibility=Post.Visibilities.public, in_reply_to__isnull=True
)
.select_related("author")
- .prefetch_related("attachments")
+ .prefetch_related("attachments", "mentions")
.order_by("-created")[:50]
)