Skip to content

Commit

Permalink
Exclude posts published over a week before we received them in federa…
Browse files Browse the repository at this point in the history
…ted and hashtag timelines
  • Loading branch information
dcwatson committed May 4, 2024
1 parent f63a121 commit c3f532c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion activities/services/post.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
from datetime import timedelta

from django.db.models import OuterRef
from django.db.models.expressions import F

from activities.models import (
Post,
Expand All @@ -20,7 +22,7 @@ class PostService:
"""

@classmethod
def queryset(cls, include_reply_to_author=False):
def queryset(cls, include_reply_to_author=False, exclude_threshold=None):
"""
Returns the base queryset to use for fetching posts efficiently.
"""
Expand All @@ -36,6 +38,10 @@ def queryset(cls, include_reply_to_author=False):
"author__domain",
)
)
if exclude_threshold is not None:
qs = qs.filter(
published__gte=F("created") - timedelta(days=exclude_threshold)
)
if include_reply_to_author:
qs = qs.annotate(
in_reply_to_author_id=Post.objects.filter(
Expand Down
6 changes: 3 additions & 3 deletions activities/services/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ def local(self, domain: Domain | None = None) -> models.QuerySet[Post]:

def federated(self) -> models.QuerySet[Post]:
return (
PostService.queryset()
PostService.queryset(exclude_threshold=7)
.public()
.filter(author__restriction=Identity.Restriction.none)
.order_by("-id")
)

def hashtag(self, hashtag: str | Hashtag) -> models.QuerySet[Post]:
return (
PostService.queryset()
PostService.queryset(exclude_threshold=7)
.public()
.filter(author__restriction=Identity.Restriction.none)
.tagged_with(hashtag)
.order_by("-published")
.order_by("-id")
)

def notifications(self, types: list[str]) -> models.QuerySet[TimelineEvent]:
Expand Down

0 comments on commit c3f532c

Please sign in to comment.