coalesce
All checks were successful
Deploy on push / deploy (push) Successful in 1m37s

This commit is contained in:
Untone 2024-02-23 21:34:02 +03:00
parent 586672b279
commit 2f81a5cf12

View File

@ -164,7 +164,6 @@ def author_follows_authors(author_id: int):
return authors return authors
def author_follows_topics(author_id: int): def author_follows_topics(author_id: int):
subquery_shout_topic = ( subquery_shout_topic = (
select( select(
@ -199,34 +198,27 @@ def author_follows_topics(author_id: int):
.alias() .alias()
) )
subq_shout_topic_alias = alias(subquery_shout_topic)
subq_shout_topic_authors_alias = alias(
subquery_shout_topic_authors, name='subq_shout_topic_authors'
)
subq_topic_followers_alias = alias(
subquery_topic_followers, name='subq_topic_followers'
)
topics_query = ( topics_query = (
select( select(
[ [
Topic, Topic,
subq_shout_topic_alias.columns.shouts_stat, func.coalesce(subquery_shout_topic.columns.shouts_stat, 0).label('shouts_stat'),
subq_shout_topic_authors_alias.columns.authors_stat, func.coalesce(subquery_shout_topic_authors.columns.authors_stat, 0).label('authors_stat'),
subq_topic_followers_alias.columns.followers_stat, func.coalesce(subquery_topic_followers.columns.followers_stat, 0).label('followers_stat'),
] ]
) )
.select_from(Topic) .select_from(Topic)
.outerjoin( .outerjoin(
subq_shout_topic_alias, Topic.id == subq_shout_topic_alias.columns.topic subquery_shout_topic,
Topic.id == subquery_shout_topic.columns.topic,
) )
.outerjoin( .outerjoin(
subq_shout_topic_authors_alias, subquery_shout_topic_authors,
Topic.id == subq_shout_topic_authors_alias.columns.topic, Topic.id == subquery_shout_topic_authors.columns.topic,
) )
.outerjoin( .outerjoin(
subq_topic_followers_alias, subquery_topic_followers,
Topic.id == subq_topic_followers_alias.columns.topic, Topic.id == subquery_topic_followers.columns.topic,
) )
) )
@ -234,6 +226,7 @@ def author_follows_topics(author_id: int):
return topics return topics
def query_follows(author_id: int): def query_follows(author_id: int):
try: try:
topics = author_follows_topics(author_id) topics = author_follows_topics(author_id)