From 7a4c4248df14e703a21477492b9612ca1a84d892 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 22 May 2021 18:34:34 -0700 Subject: [PATCH] Improves status template performance Reduces queries about about 65 --- bookwyrm/activitystreams.py | 2 ++ bookwyrm/templates/layout.html | 6 +++-- bookwyrm/templates/snippets/boost_button.html | 24 ++++++++++++++++--- bookwyrm/templates/snippets/fav_button.html | 6 +++-- .../templates/snippets/status/layout.html | 2 +- .../snippets/status/status_options.html | 4 ++-- bookwyrm/templatetags/interaction.py | 8 ++----- bookwyrm/templatetags/status_display.py | 7 +++++- 8 files changed, 42 insertions(+), 17 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 86321cd8..ff3c55fb 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -55,6 +55,8 @@ class ActivityStream(RedisStore): return ( models.Status.objects.select_subclasses() .filter(id__in=statuses) + .select_related("user", "reply_parent") + .prefetch_related("mention_books", "mention_users") .order_by("-published_date") ) diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index d5a2087e..1158d82d 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -134,12 +134,14 @@ {% trans "Notifications" %} + {% with request.user.unread_notification_count as notification_count %} - {{ request.user.unread_notification_count }} + {{ notification_count }} + {% endwith %} {% else %} diff --git a/bookwyrm/templates/snippets/boost_button.html b/bookwyrm/templates/snippets/boost_button.html index 5b84ea44..0f927406 100644 --- a/bookwyrm/templates/snippets/boost_button.html +++ b/bookwyrm/templates/snippets/boost_button.html @@ -3,14 +3,31 @@ {% load i18n %} {% with status.id|uuid as uuid %} -
+{% with request.user|boosted:status as boosted %} + {% csrf_token %} -
-
+ {% csrf_token %}
{% endwith %} +{% endwith %} diff --git a/bookwyrm/templates/snippets/fav_button.html b/bookwyrm/templates/snippets/fav_button.html index 40fa2d25..6c4cfe9a 100644 --- a/bookwyrm/templates/snippets/fav_button.html +++ b/bookwyrm/templates/snippets/fav_button.html @@ -3,7 +3,8 @@ {% load i18n %} {% with status.id|uuid as uuid %} -
+{% with request.user|liked:status as liked %} + {% csrf_token %}
-
+ {% csrf_token %}
{% endwith %} +{% endwith %} diff --git a/bookwyrm/templates/snippets/status/layout.html b/bookwyrm/templates/snippets/status/layout.html index 6fd7ebde..b1d361fe 100644 --- a/bookwyrm/templates/snippets/status/layout.html +++ b/bookwyrm/templates/snippets/status/layout.html @@ -15,7 +15,7 @@