optimize feed

This commit is contained in:
Your Name 2024-06-18 11:20:45 -04:00 committed by Henri Dickson
parent b87a71d5a5
commit 4154668a91
4 changed files with 28 additions and 28 deletions

View file

@ -30,7 +30,7 @@ def liked_post(context, post):
return ( return (
user user
and user.is_authenticated and user.is_authenticated
and Takahe.post_liked_by(post.pk, user.identity.pk) and post.interactions.filter(identity_id=user.identity.pk, type="like").exists()
) )
@ -40,5 +40,7 @@ def boosted_post(context, post):
return ( return (
user user
and user.is_authenticated and user.is_authenticated
and Takahe.post_boosted_by(post.pk, user.identity.pk) and post.interactions.filter(
identity_id=user.identity.pk, type="boost"
).exists()
) )

@ -1 +1 @@
Subproject commit cb53b38b3e8de79233867de3e89459ce820c1e58 Subproject commit 9b57e4f24413b1b335987ca8575e08b400e7fb41

View file

@ -8,7 +8,7 @@
{% load user_actions %} {% load user_actions %}
{% load duration %} {% load duration %}
{% for event in events %} {% for event in events %}
{% with event.subject_post as post %} {% with post=event.subject_post piece=event.subject_post.piece item=event.subject_post.piece.item %}
{% if not post %} {% if not post %}
<!-- invalid data {{ event.pk }} --> <!-- invalid data {{ event.pk }} -->
{% else %} {% else %}
@ -34,22 +34,22 @@
<div style="flex-grow:1;"> <div style="flex-grow:1;">
<span class="action"> <span class="action">
<span class="timestamp">{{ post.published|naturaldelta }}</span> <span class="timestamp">{{ post.published|naturaldelta }}</span>
{% if post.piece and post.piece.item and post.piece.item.class_name != 'tvepisode' %} {% if item and item.class_name != 'tvepisode' %}
<span> <span>
{% if post.piece.item.class_name == 'podcastepisode' %} {% if item.class_name == 'podcastepisode' %}
<a title="{% trans "play" %}" <a title="{% trans "play" %}"
class="episode" class="episode"
data-uuid="{{ post.piece.item.uuid }}" data-uuid="{{ item.uuid }}"
data-media="{{ post.piece.item.media_url }}" data-media="{{ item.media_url }}"
data-cover="{{ post.piece.item.cover_url|default:post.piece.item.parent_item.cover.url }}" data-cover="{{ item.cover_url|default:item.parent_item.cover.url }}"
data-title="{{ post.piece.item.title }}" data-title="{{ item.title }}"
data-album="{{ post.piece.item.parent_item.title }}" data-album="{{ item.parent_item.title }}"
data-hosts="{{ post.piece.item.parent_item.hosts|join:' / ' }}" data-hosts="{{ item.parent_item.hosts|join:' / ' }}"
{% if request.user.is_authenticated %} data-comment-href="{% url 'journal:comment' post.piece.item.uuid %}" {% endif %} {% if request.user.is_authenticated %} data-comment-href="{% url 'journal:comment' item.uuid %}" {% endif %}
data-position="{{ post.piece.metadata.position | default:0 }}"><i class="fa-solid fa-circle-play"></i></a> data-position="{{ piece.metadata.position | default:0 }}"><i class="fa-solid fa-circle-play"></i></a>
{% else %} {% else %}
<a title="{% trans "mark" %}" <a title="{% trans "mark" %}"
hx-get="{% url 'journal:mark' post.piece.item.uuid %}?shelf_type=wishlist" hx-get="{% url 'journal:mark' item.uuid %}?shelf_type=wishlist"
hx-target="body" hx-target="body"
hx-swap="beforeend"> hx-swap="beforeend">
<i class="fa-regular fa-bookmark"></i> <i class="fa-regular fa-bookmark"></i>
@ -66,7 +66,7 @@
<a href="{{ post.author.url }}" <a href="{{ post.author.url }}"
class="nickname" class="nickname"
title="@{{ post.author.handle }}">{{ post.author.name }}</a> title="@{{ post.author.handle }}">{{ post.author.name }}</a>
{% if post.piece and post.piece.classname == 'note' %} {% if piece and piece.classname == 'note' %}
{% trans "wrote a note" %} {% trans "wrote a note" %}
{% endif %} {% endif %}
</span> </span>
@ -88,7 +88,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
{% if post.piece and post.piece.classname == 'note' %} {% if piece and piece.classname == 'note' %}
<blockquote class="tldr" <blockquote class="tldr"
_="on click toggle .tldr on me" _="on click toggle .tldr on me"
style="margin:0; style="margin:0;
@ -102,12 +102,10 @@
</div> </div>
<div class="cover"> <div class="cover">
{% if post.piece %} {% if post.piece %}
{% if post.piece.item %} {% if item %}
{# <article>{% include "_item_card.html" with item=post.piece.item allow_embed=1 %}</article> #} {# <article>{% include "_item_card.html" with item=item allow_embed=1 %}</article> #}
<a href="{{ post.piece.item.url }}" title="{{ post.piece.item.title }}"> <a href="{{ item.url }}" title="{{ item.title }}">
<img src="{{ post.piece.item.cover_image_url }}" <img src="{{ item.cover_image_url }}" title="{{ item.title }}" alt="cover">
title="{{ post.piece.item.title }}"
alt="cover">
</a> </a>
{% endif %} {% endif %}
{% endif %} {% endif %}

View file

@ -68,17 +68,17 @@ def data(request):
.select_related( .select_related(
"subject_post", "subject_post",
"subject_post__author", "subject_post__author",
"subject_post__author__domain", # "subject_post__author__domain",
"subject_identity", "subject_identity",
"subject_identity__domain", # "subject_identity__domain",
"subject_post_interaction", "subject_post_interaction",
"subject_post_interaction__identity", "subject_post_interaction__identity",
"subject_post_interaction__identity__domain", # "subject_post_interaction__identity__domain",
) )
.prefetch_related( .prefetch_related(
"subject_post__attachments", "subject_post__attachments",
"subject_post__mentions", # "subject_post__mentions",
"subject_post__emojis", # "subject_post__emojis",
) )
) )
if since_id: if since_id: