From 9ea6c6c71a3abc0d7369e74b3e578466a4a4d2ef Mon Sep 17 00:00:00 2001 From: knst-kotov Date: Fri, 17 Dec 2021 15:27:16 +0100 Subject: [PATCH] fix shoutsByCommunity --- resolvers/zine.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/resolvers/zine.py b/resolvers/zine.py index 92ee6830..68b7afa9 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -375,12 +375,13 @@ async def shouts_by_author(_, info, author, limit): @query.field("shoutsByCommunity") async def shouts_by_community(_, info, community, limit): with local_session() as session: - topics = select(Topic.slug).\ - where(Topic.community == community).cte() - shouts = session.query(Shout).\ + #TODO fix postgres high load + shouts = session.query(Shout).distinct().\ join(ShoutTopic).\ - where(ShoutTopic.topic.in_(topics)).\ + where(ShoutTopic.topic.in_(\ + select(Topic.slug).where(Topic.community == community)\ + )).\ order_by(desc(Shout.createdAt)).\ - limit(limit) #TODO fix limit + limit(limit) return shouts