From 8b377123e14a401c43cfc6874deb05a38e68ecd3 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 7 Aug 2024 18:06:31 +0300 Subject: [PATCH] follower-groupby2 --- resolvers/reader.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index 5c41a203..c5ed8a29 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -82,7 +82,9 @@ def query_shouts(): Shout, ShoutReactionsFollower, func.count(case((aliased_reaction.body.is_not(None), 1))).label("comments_stat"), - func.count(ShoutReactionsFollower.follower).filter(ShoutReactionsFollower.shout == Shout.id).label("followers_stat"), + func.count(ShoutReactionsFollower.follower) + .filter(ShoutReactionsFollower.shout == Shout.id) + .label("followers_stat"), func.sum( case( (aliased_reaction.kind == ReactionKind.LIKE.value, 1), @@ -98,7 +100,13 @@ def query_shouts(): .outerjoin(authors_subquery, authors_subquery.c.shout_id == Shout.id) .outerjoin(topics_subquery, topics_subquery.c.shout_id == Shout.id) .where(and_(Shout.published_at.is_not(None), Shout.deleted_at.is_(None))) - .group_by(Shout.id, authors_subquery.c.authors, topics_subquery.c.topics, ShoutReactionsFollower.follower) + .group_by( + Shout.id, + authors_subquery.c.authors, + topics_subquery.c.topics, + ShoutReactionsFollower.follower, + ShoutReactionsFollower.shout, + ) ) return q, aliased_reaction