From 9b4fe456e8c5c70690226bdae18b6c88e687f576 Mon Sep 17 00:00:00 2001 From: Simone Robutti Date: Wed, 7 Dec 2022 22:58:30 +0100 Subject: [PATCH] removed redundant fetch --- mobilizon_reshare/dataclasses/to_split.py | 2 -- mobilizon_reshare/storage/query/read.py | 7 ++++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mobilizon_reshare/dataclasses/to_split.py b/mobilizon_reshare/dataclasses/to_split.py index 7f271d5..4204e76 100644 --- a/mobilizon_reshare/dataclasses/to_split.py +++ b/mobilizon_reshare/dataclasses/to_split.py @@ -35,8 +35,6 @@ async def get_publication(publication_id: UUID): publication = await prefetch_publication_relations( Publication.get(id=publication_id).first() ) - # TODO: this is redundant but there's some prefetch problem otherwise - publication.event = await get_event(publication.event.mobilizon_id) return EventPublication.from_orm( event=MobilizonEvent.from_model(publication.event), model=publication ) diff --git a/mobilizon_reshare/storage/query/read.py b/mobilizon_reshare/storage/query/read.py index 6f43c5a..e5e2f27 100644 --- a/mobilizon_reshare/storage/query/read.py +++ b/mobilizon_reshare/storage/query/read.py @@ -43,7 +43,12 @@ async def prefetch_publication_relations( queryset: QuerySet[Publication], ) -> list[Publication]: publication = ( - await queryset.prefetch_related("publisher", "event") + await queryset.prefetch_related( + "publisher", + "event", + "event__publications", + "event__publications__publisher", + ) .order_by("timestamp") .distinct() )