- - {% trans 'Popular Tags' %} - - {% for t in popular_tags %} - - {{ t }} - - {% empty %} - {% trans "nothing so far." %} - {% endfor %} - - -
diff --git a/journal/models/tag.py b/journal/models/tag.py index fc11738f..27bdbad8 100644 --- a/journal/models/tag.py +++ b/journal/models/tag.py @@ -129,7 +129,7 @@ class TagManager: return TagManager.all_tags_by_owner(self.owner, public_only=True) @staticmethod - def popular_tags(days: int = 30, limit: int = 20): + def popular_tags(days: int = 30): t = timezone.now() - timedelta(days=days) titles = ( TagMember.objects.filter(created_time__gt=t) @@ -138,7 +138,7 @@ class TagManager: .values("title") .annotate(total=Count("parent_id", distinct=True)) .order_by("-total") - .values_list("title", flat=True)[:limit] + .values_list("title", flat=True) ) return titles diff --git a/takahe/utils.py b/takahe/utils.py index 01bab0a5..5470b4af 100644 --- a/takahe/utils.py +++ b/takahe/utils.py @@ -973,8 +973,8 @@ class Takahe: ) @staticmethod - def get_popular_posts(days: int = 14, limit: int = 20): - since = timezone.now().date() - timedelta(days=days) + def get_popular_posts(days: int = 30, min_interaction: int = 1): + since = timezone.now() - timedelta(days=days) domains = Takahe.get_neodb_peers() + [settings.SITE_DOMAIN] return ( Post.objects.exclude(state__in=["deleted", "deleted_fanned_out"]) @@ -982,8 +982,8 @@ class Takahe: author__domain__in=domains, visibility__in=[0, 4], published__gte=since ) .annotate(num_interactions=Count("interactions")) - .filter(num_interactions__gt=0) - .order_by("-num_interactions", "-published")[:limit] + .filter(num_interactions__gte=min_interaction) + .order_by("-num_interactions", "-published") ) @staticmethod