This commit is contained in:
Untone 2023-11-30 16:07:30 +03:00
parent 5f0a8f3b10
commit f1ccef7919
2 changed files with 7 additions and 11 deletions

View File

@ -140,10 +140,9 @@ async def load_shouts_by(_, info, options):
""" """
q = ( q = (
select(Shout) select(Shout, Author)
.options( .options(
# joinedload(Shout.created_by, Author.id == Shout.created_by), joinedload(Shout.authors, Shout.authors.contains(Author.id)),
joinedload(Shout.authors),
joinedload(Shout.topics), joinedload(Shout.topics),
) )
.where(Shout.deleted_at.is_(None)) .where(Shout.deleted_at.is_(None))

View File

@ -23,20 +23,17 @@ def add_topic_stat_columns(q):
q = ( q = (
q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topic) q.outerjoin(ShoutTopic, Topic.id == ShoutTopic.topic)
.add_columns(func.count(distinct(ShoutTopic.shout)) .add_columns(func.count(distinct(ShoutTopic.shout)).label("shouts_stat"))
.label("shouts_stat"))
.outerjoin(aliased_shout_author, ShoutTopic.shout == aliased_shout_author.shout) .outerjoin(aliased_shout_author, ShoutTopic.shout == aliased_shout_author.shout)
.add_columns(func.count(distinct(aliased_shout_author.author)) .add_columns(func.count(distinct(aliased_shout_author.user)).label("authors_stat"))
.label("authors_stat"))
.outerjoin(aliased_topic_follower) .outerjoin(aliased_topic_follower)
.add_columns(func.count(distinct(aliased_topic_follower.follower)) .add_columns(func.count(distinct(aliased_topic_follower.follower)).label("followers_stat"))
.label("followers_stat"))
) )
q = q.group_by(Topic.id) q = q.group_by(Topic.id)
print(f"[resolvers.topics] Generated SQL: {str(q)}") # Add this line for debugging
return q return q