forked from mirrors/bookwyrm
Improves status template performance
Reduces queries about about 65
This commit is contained in:
parent
e5ff4ac36d
commit
7a4c4248df
8 changed files with 42 additions and 17 deletions
|
@ -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")
|
||||
)
|
||||
|
||||
|
|
|
@ -134,12 +134,14 @@
|
|||
<span class="is-sr-only">{% trans "Notifications" %}</span>
|
||||
</span>
|
||||
</span>
|
||||
{% with request.user.unread_notification_count as notification_count %}
|
||||
<span
|
||||
class="{% if not request.user.unread_notification_count %}is-hidden {% elif request.user.has_unread_mentions %}is-danger {% endif %}tag is-medium transition-x"
|
||||
class="{% if not notification_count %}is-hidden {% elif request.user.has_unread_mentions %}is-danger {% endif %}tag is-medium transition-x"
|
||||
data-poll-wrapper
|
||||
>
|
||||
<span data-poll="notifications">{{ request.user.unread_notification_count }}</span>
|
||||
<span data-poll="notifications">{{ notification_count }}</span>
|
||||
</span>
|
||||
{% endwith %}
|
||||
</a>
|
||||
</div>
|
||||
{% else %}
|
||||
|
|
|
@ -3,14 +3,31 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% with status.id|uuid as uuid %}
|
||||
<form name="boost" action="/boost/{{ status.id }}" method="post" class="interaction boost-{{ status.id }}-{{ uuid }} {% if request.user|boosted:status %}is-hidden{% endif %}" data-id="boost-{{ status.id }}-{{ uuid }}">
|
||||
{% with request.user|boosted:status as boosted %}
|
||||
<form
|
||||
name="boost"
|
||||
action="/boost/{{ status.id }}"
|
||||
method="post"
|
||||
class="interaction boost-{{ status.id }}-{{ uuid }} {% if boosted %}is-hidden{% endif %}"
|
||||
data-id="boost-{{ status.id }}-{{ uuid }}"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<button class="button is-small is-light is-transparent" type="submit" {% if not status.boostable %}disabled{% endif %}>
|
||||
<button
|
||||
class="button is-small is-light is-transparent"
|
||||
type="submit"
|
||||
{% if not status.boostable %}disabled{% endif %}
|
||||
>
|
||||
<span class="icon icon-boost m-0-mobile" title="{% trans 'Boost' %}"></span>
|
||||
<span class="is-sr-only-mobile">{% trans "Boost" %}</span>
|
||||
</button>
|
||||
</form>
|
||||
<form name="unboost" action="/unboost/{{ status.id }}" method="post" class="interaction boost-{{ status.id }}-{{ uuid }} active {% if not request.user|boosted:status %}is-hidden{% endif %}" data-id="boost-{{ status.id }}-{{ uuid }}">
|
||||
<form
|
||||
name="unboost"
|
||||
action="/unboost/{{ status.id }}"
|
||||
method="post"
|
||||
class="interaction boost-{{ status.id }}-{{ uuid }} active {% if not boosted %}is-hidden{% endif %}"
|
||||
data-id="boost-{{ status.id }}-{{ uuid }}"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<button class="button is-small is-light is-transparent" type="submit">
|
||||
<span class="icon icon-boost has-text-primary m-0-mobile" title="{% trans 'Un-boost' %}"></span>
|
||||
|
@ -18,3 +35,4 @@
|
|||
</button>
|
||||
</form>
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% with status.id|uuid as uuid %}
|
||||
<form name="favorite" action="/favorite/{{ status.id }}" method="POST" class="interaction fav-{{ status.id }}-{{ uuid }} {% if request.user|liked:status %}is-hidden{% endif %}" data-id="fav-{{ status.id }}-{{ uuid }}">
|
||||
{% with request.user|liked:status as liked %}
|
||||
<form name="favorite" action="/favorite/{{ status.id }}" method="POST" class="interaction fav-{{ status.id }}-{{ uuid }} {% if liked %}is-hidden{% endif %}" data-id="fav-{{ status.id }}-{{ uuid }}">
|
||||
{% csrf_token %}
|
||||
<button class="button is-small is-light is-transparent" type="submit">
|
||||
<span class="icon icon-heart m-0-mobile" title="{% trans 'Like' %}">
|
||||
|
@ -11,7 +12,7 @@
|
|||
<span class="is-sr-only-mobile">{% trans "Like" %}</span>
|
||||
</button>
|
||||
</form>
|
||||
<form name="unfavorite" action="/unfavorite/{{ status.id }}" method="POST" class="interaction fav-{{ status.id }}-{{ uuid }} active {% if not request.user|liked:status %}is-hidden{% endif %}" data-id="fav-{{ status.id }}-{{ uuid }}">
|
||||
<form name="unfavorite" action="/unfavorite/{{ status.id }}" method="POST" class="interaction fav-{{ status.id }}-{{ uuid }} active {% if not liked %}is-hidden{% endif %}" data-id="fav-{{ status.id }}-{{ uuid }}">
|
||||
{% csrf_token %}
|
||||
<button class="button is-light is-transparent is-small" type="submit">
|
||||
<span class="icon icon-heart has-text-primary m-0-mobile" title="{% trans 'Un-like' %}"></span>
|
||||
|
@ -19,3 +20,4 @@
|
|||
</button>
|
||||
</form>
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<div class="card-footer-item">
|
||||
|
||||
{# moderation options #}
|
||||
<form name="delete-{{status.id}}" action="/delete-status/{{ status.id }}" method="post">
|
||||
<form name="delete-{{ status.id }}" action="/delete-status/{{ status.id }}" method="post">
|
||||
{% csrf_token %}
|
||||
<button class="button is-danger is-light" type="submit">
|
||||
{% trans "Delete status" %}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
{% if status.user == request.user %}
|
||||
{# things you can do to your own statuses #}
|
||||
<li role="menuitem" class="dropdown-item p-0">
|
||||
<form name="delete-{{status.id}}" action="/delete-status/{{ status.id }}" method="post">
|
||||
<form name="delete-{{ status.id }}" action="/delete-status/{{ status.id }}" method="post">
|
||||
{% csrf_token %}
|
||||
<button class="button is-radiusless is-danger is-light is-fullwidth is-small" type="submit">
|
||||
{% trans "Delete status" %}
|
||||
|
@ -20,7 +20,7 @@
|
|||
</li>
|
||||
{% if status.status_type != 'GeneratedNote' and status.status_type != 'Rating' %}
|
||||
<li role="menuitem" class="dropdown-item p-0">
|
||||
<form class="" name="delete-{{status.id}}" action="{% url 'redraft' status.id %}" method="post">
|
||||
<form class="" name="delete-{{ status.id }}" action="{% url 'redraft' status.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
<button class="button is-radiusless is-danger is-light is-fullwidth is-small" type="submit">
|
||||
{% trans "Delete & re-draft" %}
|
||||
|
|
|
@ -9,14 +9,10 @@ register = template.Library()
|
|||
@register.filter(name="liked")
|
||||
def get_user_liked(user, status):
|
||||
"""did the given user fav a status?"""
|
||||
try:
|
||||
models.Favorite.objects.get(user=user, status=status)
|
||||
return True
|
||||
except models.Favorite.DoesNotExist:
|
||||
return False
|
||||
return models.Favorite.objects.filter(user=user, status=status).exists()
|
||||
|
||||
|
||||
@register.filter(name="boosted")
|
||||
def get_user_boosted(user, status):
|
||||
"""did the given user fav a status?"""
|
||||
return user.id in status.boosters.all().values_list("user", flat=True)
|
||||
return status.boosters.filter(user=user).exists()
|
||||
|
|
|
@ -42,7 +42,12 @@ def get_parent(status):
|
|||
@register.filter(name="boosted_status")
|
||||
def get_boosted(boost):
|
||||
"""load a boosted status. have to do this or it won't get foreign keys"""
|
||||
return models.Status.objects.select_subclasses().get(id=boost.boosted_status.id)
|
||||
return (
|
||||
models.Status.objects.select_subclasses()
|
||||
.select_related("user", "reply_parent")
|
||||
.prefetch_related("mention_books", "mention_users")
|
||||
.get(id=boost.boosted_status.id)
|
||||
)
|
||||
|
||||
|
||||
@register.filter(name="published_date")
|
||||
|
|
Loading…
Reference in a new issue