From f1ccef7919a53f7990bbfda4fade4b7a96f1d3fd Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 30 Nov 2023 16:07:30 +0300 Subject: [PATCH] no-debug --- resolvers/reader.py | 5 ++--- resolvers/topic.py | 13 +++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index 475c254f..f2db587e 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -140,10 +140,9 @@ async def load_shouts_by(_, info, options): """ q = ( - select(Shout) + select(Shout, Author) .options( - # joinedload(Shout.created_by, Author.id == Shout.created_by), - joinedload(Shout.authors), + joinedload(Shout.authors, Shout.authors.contains(Author.id)), joinedload(Shout.topics), ) .where(Shout.deleted_at.is_(None)) diff --git a/resolvers/topic.py b/resolvers/topic.py index 4ad59c7c..571a9105 100644 --- a/resolvers/topic.py +++ b/resolvers/topic.py @@ -23,20 +23,17 @@ def add_topic_stat_columns(q): q = ( q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topic) - .add_columns(func.count(distinct(ShoutTopic.shout)) - .label("shouts_stat")) + .add_columns(func.count(distinct(ShoutTopic.shout)).label("shouts_stat")) + .outerjoin(aliased_shout_author, ShoutTopic.shout == aliased_shout_author.shout) - .add_columns(func.count(distinct(aliased_shout_author.author)) - .label("authors_stat")) + .add_columns(func.count(distinct(aliased_shout_author.user)).label("authors_stat")) + .outerjoin(aliased_topic_follower) - .add_columns(func.count(distinct(aliased_topic_follower.follower)) - .label("followers_stat")) + .add_columns(func.count(distinct(aliased_topic_follower.follower)).label("followers_stat")) ) q = q.group_by(Topic.id) - print(f"[resolvers.topics] Generated SQL: {str(q)}") # Add this line for debugging - return q