nodistinct
Some checks failed
Deploy on push / deploy (push) Failing after 9s

This commit is contained in:
2024-08-09 08:17:40 +03:00
parent 71db929fa4
commit d0c1f33227
2 changed files with 319 additions and 397 deletions

View File

@@ -83,8 +83,10 @@ def query_shouts(slug=None):
q = (
select(
Shout,
func.count().filter(aliased_reaction.kind == ReactionKind.COMMENT.value).label("comments_stat"),
func.count(distinct(ShoutReactionsFollower.follower)).label("followers_stat"),
func.count(aliased_reaction.id)
.filter(aliased_reaction.kind == ReactionKind.COMMENT.value)
.label("comments_stat"),
func.count(ShoutReactionsFollower.follower).label("followers_stat"),
func.sum(
case(
(aliased_reaction.kind == ReactionKind.LIKE.value, 1),
@@ -97,7 +99,7 @@ def query_shouts(slug=None):
topics_subquery.c.topics.label("topics"),
topics_subquery.c.main_topic_slug.label("main_topic_slug"),
)
.outerjoin(aliased_reaction, aliased_reaction.shout == Shout.id)
.outerjoin(aliased_reaction, and_(aliased_reaction.shout == Shout.id, aliased_reaction.deleted_at.is_(None)))
.outerjoin(authors_subquery, authors_subquery.c.shout_id == Shout.id)
.outerjoin(topics_subquery, topics_subquery.c.shout_id == Shout.id)
.outerjoin(ShoutReactionsFollower, ShoutReactionsFollower.shout == Shout.id)