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.
This commit is contained in:
Andrew Godwin 2023-01-14 11:31:17 -07:00
parent ade954c2cd
commit 76076e3387
3 changed files with 11 additions and 9 deletions

View file

@ -853,7 +853,7 @@ class Post(StatorModel):
try: try:
parent = cls.by_object_uri(post.in_reply_to) parent = cls.by_object_uri(post.in_reply_to)
except cls.DoesNotExist: except cls.DoesNotExist:
cls.ensure_object_uri(post.in_reply_to) cls.ensure_object_uri(post.in_reply_to, reason=post.object_uri)
else: else:
parent.calculate_stats() parent.calculate_stats()
return post return post
@ -900,7 +900,7 @@ class Post(StatorModel):
raise cls.DoesNotExist(f"Cannot find Post with URI {object_uri}") raise cls.DoesNotExist(f"Cannot find Post with URI {object_uri}")
@classmethod @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 Sees if the post is in our local set, and if not, schedules a fetch
for it (in the background) for it (in the background)
@ -916,6 +916,7 @@ class Post(StatorModel):
"object": { "object": {
"type": "FetchPost", "type": "FetchPost",
"object": object_uri, "object": object_uri,
"reason": reason,
}, },
} }
) )

View file

@ -88,9 +88,10 @@ class PostService:
ancestor = self.post ancestor = self.post
while ancestor.in_reply_to and len(ancestors) < num_ancestors: while ancestor.in_reply_to and len(ancestors) < num_ancestors:
object_uri = ancestor.in_reply_to object_uri = ancestor.in_reply_to
reason = ancestor.object_uri
ancestor = self.queryset().filter(object_uri=object_uri).first() ancestor = self.queryset().filter(object_uri=object_uri).first()
if ancestor is None: if ancestor is None:
Post.ensure_object_uri(object_uri) Post.ensure_object_uri(object_uri, reason=reason)
break break
if ancestor.state in [PostStates.deleted, PostStates.deleted_fanned_out]: if ancestor.state in [PostStates.deleted, PostStates.deleted_fanned_out]:
break break

View file

@ -37,7 +37,7 @@ class TimelineService:
identity=self.identity, identity=self.identity,
type__in=[TimelineEvent.Types.post, TimelineEvent.Types.boost], type__in=[TimelineEvent.Types.post, TimelineEvent.Types.boost],
) )
.order_by("-published") .order_by("-created")
) )
def local(self) -> models.QuerySet[Post]: def local(self) -> models.QuerySet[Post]:
@ -45,7 +45,7 @@ class TimelineService:
PostService.queryset() PostService.queryset()
.local_public() .local_public()
.filter(author__restriction=Identity.Restriction.none) .filter(author__restriction=Identity.Restriction.none)
.order_by("-published") .order_by("-id")
) )
def federated(self) -> models.QuerySet[Post]: def federated(self) -> models.QuerySet[Post]:
@ -53,7 +53,7 @@ class TimelineService:
PostService.queryset() PostService.queryset()
.public() .public()
.filter(author__restriction=Identity.Restriction.none) .filter(author__restriction=Identity.Restriction.none)
.order_by("-published") .order_by("-id")
) )
def hashtag(self, hashtag: str | Hashtag) -> models.QuerySet[Post]: def hashtag(self, hashtag: str | Hashtag) -> models.QuerySet[Post]:
@ -62,14 +62,14 @@ class TimelineService:
.public() .public()
.filter(author__restriction=Identity.Restriction.none) .filter(author__restriction=Identity.Restriction.none)
.tagged_with(hashtag) .tagged_with(hashtag)
.order_by("-published") .order_by("-id")
) )
def notifications(self, types: list[str]) -> models.QuerySet[TimelineEvent]: def notifications(self, types: list[str]) -> models.QuerySet[TimelineEvent]:
return ( return (
self.event_queryset() self.event_queryset()
.filter(identity=self.identity, type__in=types) .filter(identity=self.identity, type__in=types)
.order_by("-published") .order_by("-created")
) )
def identity_public(self, identity: Identity): def identity_public(self, identity: Identity):
@ -80,5 +80,5 @@ class TimelineService:
PostService.queryset() PostService.queryset()
.filter(author=identity) .filter(author=identity)
.unlisted(include_replies=True) .unlisted(include_replies=True)
.order_by("-created") .order_by("-id")
) )