removed redundant fetch

This commit is contained in:
Simone Robutti 2022-12-07 22:58:30 +01:00
parent 0a6b98ce51
commit 9b4fe456e8
2 changed files with 6 additions and 3 deletions

View File

@ -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
)

View File

@ -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()
)