honor discover exclusions

This commit is contained in:
Your Name 2024-06-20 15:10:06 -04:00 committed by Henri Dickson
parent b855bd2eb7
commit 4fcd18cafa
3 changed files with 36 additions and 16 deletions

View file

@ -139,22 +139,33 @@ class DiscoverGenerator(BaseJob):
.values_list("pk", flat=True)[:40] .values_list("pk", flat=True)[:40]
) )
tags = TagManager.popular_tags(days=14)[:40] tags = TagManager.popular_tags(days=14)[:40]
excluding_identities = Takahe.get_no_discover_identities()
post_ids = ( post_ids = (
set( set(
Takahe.get_popular_posts( Takahe.get_popular_posts(
28, settings.MIN_MARKS_FOR_DISCOVER 28, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities
).values_list("pk", flat=True)[:20] ).values_list("pk", flat=True)[:5]
) )
| set( | set(
Takahe.get_popular_posts( Takahe.get_popular_posts(
7, settings.MIN_MARKS_FOR_DISCOVER 14, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities
).values_list("pk", flat=True)[:5]
)
| set(
Takahe.get_popular_posts(
7, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities
).values_list("pk", flat=True)[:10] ).values_list("pk", flat=True)[:10]
) )
| set(Takahe.get_popular_posts(1, 0).values_list("pk", flat=True)[:3]) | set(
Takahe.get_popular_posts(1, 0, excluding_identities).values_list(
"pk", flat=True
)[:3]
)
| set( | set(
Review.objects.filter(visibility=0) Review.objects.filter(visibility=0)
.exclude(owner_id__in=excluding_identities)
.order_by("-created_time") .order_by("-created_time")
.values_list("posts", flat=True)[:3] .values_list("posts", flat=True)[:5]
) )
) )
cache.set("public_gallery", gallery_list, timeout=None) cache.set("public_gallery", gallery_list, timeout=None)
@ -163,5 +174,5 @@ class DiscoverGenerator(BaseJob):
cache.set("popular_tags", list(tags), timeout=None) cache.set("popular_tags", list(tags), timeout=None)
cache.set("popular_posts", list(post_ids), timeout=None) cache.set("popular_posts", list(post_ids), timeout=None)
logger.info( logger.info(
f"Discover data updated, trends: {len(trends)}, collections: {len(collection_ids)}, tags: {len(tags)}, posts: {len(post_ids)}." f"Discover data updated, excluded: {len(excluding_identities)}, trends: {len(trends)}, collections: {len(collection_ids)}, tags: {len(tags)}, posts: {len(post_ids)}."
) )

View file

@ -166,15 +166,7 @@
{% endif %} {% endif %}
<section> <section>
<article> <article>
<details id="section-popular-posts" class="auto-keep-collapse" open> <details id="section-popular-tags" class="auto-keep-collapse">
<summary>{% trans 'Popular Posts' %}</summary>
<div style="font-size:80%">{% include "posts.html" with posts=popular_posts %}</div>
</details>
</article>
</section>
<section>
<article>
<details id="section-popular-tags" class="auto-keep-collapse" open>
<summary>{% trans 'Popular Tags' %}</summary> <summary>{% trans 'Popular Tags' %}</summary>
<div class="tag-list"> <div class="tag-list">
{% for t in popular_tags %} {% for t in popular_tags %}
@ -188,6 +180,14 @@
</details> </details>
</article> </article>
</section> </section>
<section>
<article>
<details id="section-popular-posts" class="auto-keep-collapse" open>
<summary>{% trans 'Popular Posts' %}</summary>
<div style="font-size:80%">{% include "posts.html" with posts=popular_posts %}</div>
</details>
</article>
</section>
</aside> </aside>
{% else %} {% else %}
{% include "_sidebar_anonymous.html" %} {% include "_sidebar_anonymous.html" %}

View file

@ -911,11 +911,20 @@ class Takahe:
) )
@staticmethod @staticmethod
def get_popular_posts(days: int = 30, min_interaction: int = 1): def get_no_discover_identities():
return list(
Identity.objects.filter(discoverable=False).values_list("pk", flat=True)
)
@staticmethod
def get_popular_posts(
days: int = 30, min_interaction: int = 1, exclude_identities: list[int] = []
):
since = timezone.now() - timedelta(days=days) since = timezone.now() - timedelta(days=days)
domains = Takahe.get_neodb_peers() + [settings.SITE_DOMAIN] domains = Takahe.get_neodb_peers() + [settings.SITE_DOMAIN]
return ( return (
Post.objects.exclude(state__in=["deleted", "deleted_fanned_out"]) Post.objects.exclude(state__in=["deleted", "deleted_fanned_out"])
.exclude(author_id__in=exclude_identities)
.filter( .filter(
author__domain__in=domains, author__domain__in=domains,
visibility__in=[0, 1, 4], visibility__in=[0, 1, 4],