Refactors block button for query efficiency

This commit is contained in:
Mouse Reeve 2021-05-22 20:36:30 -07:00
parent 9285f483c2
commit bdf267dea5
6 changed files with 13 additions and 8 deletions

View file

@ -18,7 +18,7 @@
<a href="{{ user.local_path }}">{% include 'snippets/avatar.html' with user=user %} {{ user.display_name }}</a>
</p>
<p class="mr-2">
{% include 'snippets/block_button.html' with user=user %}
{% include 'snippets/block_button.html' with user=user blocks=True %}
</p>
</li>
{% endfor %}

View file

@ -1,5 +1,5 @@
{% load i18n %}
{% if not user in request.user.blocks.all %}
{% if not blocks %}
<form name="blocks" method="post" action="/block/{{ user.id }}">
{% csrf_token %}
<button class="button is-danger is-light is-small {{ class }}" type="submit">{% trans "Block" %}</button>

View file

@ -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 %}
<div class="field{% if not minimal %} has-addons{% else %} mb-0{% endif %}">

View file

@ -39,7 +39,7 @@
{% include 'snippets/report_button.html' with user=status.user status=status %}
</li>
<li role="menuitem" class="dropdown-item p-0">
{% include 'snippets/block_button.html' with user=status.user class="is-fullwidth" %}
{% include 'snippets/block_button.html' with user=status.user class="is-fullwidth" blocks=False %}
</li>
{% endif %}
{% endblock %}

View file

@ -16,6 +16,6 @@
{% include 'snippets/report_button.html' with user=user class="is-fullwidth" %}
</li>
<li role="menuitem">
{% include 'snippets/block_button.html' with user=user class="is-fullwidth" %}
{% include 'snippets/block_button.html' with user=user class="is-fullwidth" blocks=False %}
</li>
{% endblock %}

View file

@ -59,10 +59,15 @@ class User(View):
break
# user's posts
activities = privacy_filter(
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