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 (
user
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 (
user
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 duration %}
{% 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 %}
<!-- invalid data {{ event.pk }} -->
{% else %}
@ -34,22 +34,22 @@
<div style="flex-grow:1;">
<span class="action">
<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>
{% if post.piece.item.class_name == 'podcastepisode' %}
{% if item.class_name == 'podcastepisode' %}
<a title="{% trans "play" %}"
class="episode"
data-uuid="{{ post.piece.item.uuid }}"
data-media="{{ post.piece.item.media_url }}"
data-cover="{{ post.piece.item.cover_url|default:post.piece.item.parent_item.cover.url }}"
data-title="{{ post.piece.item.title }}"
data-album="{{ post.piece.item.parent_item.title }}"
data-hosts="{{ post.piece.item.parent_item.hosts|join:' / ' }}"
{% if request.user.is_authenticated %} data-comment-href="{% url 'journal:comment' post.piece.item.uuid %}" {% endif %}
data-position="{{ post.piece.metadata.position | default:0 }}"><i class="fa-solid fa-circle-play"></i></a>
data-uuid="{{ item.uuid }}"
data-media="{{ item.media_url }}"
data-cover="{{ item.cover_url|default:item.parent_item.cover.url }}"
data-title="{{ item.title }}"
data-album="{{ item.parent_item.title }}"
data-hosts="{{ item.parent_item.hosts|join:' / ' }}"
{% if request.user.is_authenticated %} data-comment-href="{% url 'journal:comment' item.uuid %}" {% endif %}
data-position="{{ piece.metadata.position | default:0 }}"><i class="fa-solid fa-circle-play"></i></a>
{% else %}
<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-swap="beforeend">
<i class="fa-regular fa-bookmark"></i>
@ -66,7 +66,7 @@
<a href="{{ post.author.url }}"
class="nickname"
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" %}
{% endif %}
</span>
@ -88,7 +88,7 @@
{% endif %}
{% endfor %}
</div>
{% if post.piece and post.piece.classname == 'note' %}
{% if piece and piece.classname == 'note' %}
<blockquote class="tldr"
_="on click toggle .tldr on me"
style="margin:0;
@ -102,12 +102,10 @@
</div>
<div class="cover">
{% if post.piece %}
{% if post.piece.item %}
{# <article>{% include "_item_card.html" with item=post.piece.item allow_embed=1 %}</article> #}
<a href="{{ post.piece.item.url }}" title="{{ post.piece.item.title }}">
<img src="{{ post.piece.item.cover_image_url }}"
title="{{ post.piece.item.title }}"
alt="cover">
{% if item %}
{# <article>{% include "_item_card.html" with item=item allow_embed=1 %}</article> #}
<a href="{{ item.url }}" title="{{ item.title }}">
<img src="{{ item.cover_image_url }}" title="{{ item.title }}" alt="cover">
</a>
{% endif %}
{% endif %}

View file

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