From bdf267dea5fa21755a274a51b3056460de61fdd7 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 22 May 2021 20:36:30 -0700 Subject: [PATCH] Refactors block button for query efficiency --- bookwyrm/templates/preferences/blocks.html | 2 +- bookwyrm/templates/snippets/block_button.html | 2 +- bookwyrm/templates/snippets/follow_button.html | 2 +- .../templates/snippets/status/status_options.html | 2 +- bookwyrm/templates/snippets/user_options.html | 2 +- bookwyrm/views/user.py | 11 ++++++++--- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bookwyrm/templates/preferences/blocks.html b/bookwyrm/templates/preferences/blocks.html index 72d4abd4..24866fa3 100644 --- a/bookwyrm/templates/preferences/blocks.html +++ b/bookwyrm/templates/preferences/blocks.html @@ -18,7 +18,7 @@ {% include 'snippets/avatar.html' with user=user %} {{ user.display_name }}

- {% include 'snippets/block_button.html' with user=user %} + {% include 'snippets/block_button.html' with user=user blocks=True %}

{% endfor %} diff --git a/bookwyrm/templates/snippets/block_button.html b/bookwyrm/templates/snippets/block_button.html index 7e9fcaea..3cad78f6 100644 --- a/bookwyrm/templates/snippets/block_button.html +++ b/bookwyrm/templates/snippets/block_button.html @@ -1,5 +1,5 @@ {% load i18n %} -{% if not user in request.user.blocks.all %} +{% if not blocks %}
{% csrf_token %} diff --git a/bookwyrm/templates/snippets/follow_button.html b/bookwyrm/templates/snippets/follow_button.html index 495bc3e9..0cbe6b8c 100644 --- a/bookwyrm/templates/snippets/follow_button.html +++ b/bookwyrm/templates/snippets/follow_button.html @@ -1,7 +1,7 @@ {% load i18n %} {% if request.user == user or not request.user.is_authenticated %} {% elif user in request.user.blocks.all %} -{% include 'snippets/block_button.html' %} +{% include 'snippets/block_button.html' with blocks=True %} {% else %}
diff --git a/bookwyrm/templates/snippets/status/status_options.html b/bookwyrm/templates/snippets/status/status_options.html index c33aeda2..7eb613d3 100644 --- a/bookwyrm/templates/snippets/status/status_options.html +++ b/bookwyrm/templates/snippets/status/status_options.html @@ -39,7 +39,7 @@ {% include 'snippets/report_button.html' with user=status.user status=status %} {% endif %} {% endblock %} diff --git a/bookwyrm/templates/snippets/user_options.html b/bookwyrm/templates/snippets/user_options.html index 01cc09bf..3db3c2b1 100644 --- a/bookwyrm/templates/snippets/user_options.html +++ b/bookwyrm/templates/snippets/user_options.html @@ -16,6 +16,6 @@ {% include 'snippets/report_button.html' with user=user class="is-fullwidth" %}
  • - {% include 'snippets/block_button.html' with user=user class="is-fullwidth" %} + {% include 'snippets/block_button.html' with user=user class="is-fullwidth" blocks=False %}
  • {% endblock %} diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index ffc352d8..d186fe97 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -59,10 +59,15 @@ class User(View): break # user's posts - activities = privacy_filter( - request.user, - user.status_set.select_subclasses(), + activities = ( + privacy_filter( + request.user, + user.status_set.select_subclasses(), + ) + .select_related("reply_parent") + .prefetch_related("mention_books", "mention_users") ) + paginated = Paginator(activities, PAGE_LENGTH) goal = models.AnnualGoal.objects.filter( user=user, year=timezone.now().year