From 76076e33877a9c5058fb2aedc461bb24c159f33f Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 14 Jan 2023 11:31:17 -0700 Subject: [PATCH] Flip timelines back to created ordering Also added in some tracking from where post fetches come from, in case this re-creates the weird thing where posts emerge from history. --- activities/models/post.py | 5 +++-- activities/services/post.py | 3 ++- activities/services/timeline.py | 12 ++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/activities/models/post.py b/activities/models/post.py index 0eceaaa..e20f690 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -853,7 +853,7 @@ class Post(StatorModel): try: parent = cls.by_object_uri(post.in_reply_to) except cls.DoesNotExist: - cls.ensure_object_uri(post.in_reply_to) + cls.ensure_object_uri(post.in_reply_to, reason=post.object_uri) else: parent.calculate_stats() return post @@ -900,7 +900,7 @@ class Post(StatorModel): raise cls.DoesNotExist(f"Cannot find Post with URI {object_uri}") @classmethod - def ensure_object_uri(cls, object_uri: str): + def ensure_object_uri(cls, object_uri: str, reason: str | None = None): """ Sees if the post is in our local set, and if not, schedules a fetch for it (in the background) @@ -916,6 +916,7 @@ class Post(StatorModel): "object": { "type": "FetchPost", "object": object_uri, + "reason": reason, }, } ) diff --git a/activities/services/post.py b/activities/services/post.py index b865a64..f2f21ca 100644 --- a/activities/services/post.py +++ b/activities/services/post.py @@ -88,9 +88,10 @@ class PostService: ancestor = self.post while ancestor.in_reply_to and len(ancestors) < num_ancestors: object_uri = ancestor.in_reply_to + reason = ancestor.object_uri ancestor = self.queryset().filter(object_uri=object_uri).first() if ancestor is None: - Post.ensure_object_uri(object_uri) + Post.ensure_object_uri(object_uri, reason=reason) break if ancestor.state in [PostStates.deleted, PostStates.deleted_fanned_out]: break diff --git a/activities/services/timeline.py b/activities/services/timeline.py index 0ca4b3e..d761d21 100644 --- a/activities/services/timeline.py +++ b/activities/services/timeline.py @@ -37,7 +37,7 @@ class TimelineService: identity=self.identity, type__in=[TimelineEvent.Types.post, TimelineEvent.Types.boost], ) - .order_by("-published") + .order_by("-created") ) def local(self) -> models.QuerySet[Post]: @@ -45,7 +45,7 @@ class TimelineService: PostService.queryset() .local_public() .filter(author__restriction=Identity.Restriction.none) - .order_by("-published") + .order_by("-id") ) def federated(self) -> models.QuerySet[Post]: @@ -53,7 +53,7 @@ class TimelineService: PostService.queryset() .public() .filter(author__restriction=Identity.Restriction.none) - .order_by("-published") + .order_by("-id") ) def hashtag(self, hashtag: str | Hashtag) -> models.QuerySet[Post]: @@ -62,14 +62,14 @@ class TimelineService: .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]: return ( self.event_queryset() .filter(identity=self.identity, type__in=types) - .order_by("-published") + .order_by("-created") ) def identity_public(self, identity: Identity): @@ -80,5 +80,5 @@ class TimelineService: PostService.queryset() .filter(author=identity) .unlisted(include_replies=True) - .order_by("-created") + .order_by("-id") )