topics-with-stat-fix
All checks were successful
Deploy on push / deploy (push) Successful in 1m23s

This commit is contained in:
Untone 2024-02-23 22:14:08 +03:00
parent 2f81a5cf12
commit f16f345040

View File

@ -164,6 +164,7 @@ 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(
@ -202,23 +203,23 @@ def author_follows_topics(author_id: int):
select( select(
[ [
Topic, Topic,
func.coalesce(subquery_shout_topic.columns.shouts_stat, 0).label('shouts_stat'), subquery_shout_topic.columns.shouts_stat,
func.coalesce(subquery_shout_topic_authors.columns.authors_stat, 0).label('authors_stat'), subquery_shout_topic_authors.columns.authors_stat,
func.coalesce(subquery_topic_followers.columns.followers_stat, 0).label('followers_stat'), subquery_topic_followers.columns.followers_stat,
] ]
) )
.select_from(Topic) .select_from(Topic)
.outerjoin( .outerjoin(
subquery_shout_topic, subquery_shout_topic,
Topic.id == subquery_shout_topic.columns.topic, Topic.id == subquery_shout_topic.c.topic,
) )
.outerjoin( .outerjoin(
subquery_shout_topic_authors, subquery_shout_topic_authors,
Topic.id == subquery_shout_topic_authors.columns.topic, Topic.id == subquery_shout_topic_authors.c.topic,
) )
.outerjoin( .outerjoin(
subquery_topic_followers, subquery_topic_followers,
Topic.id == subquery_topic_followers.columns.topic, Topic.id == subquery_topic_followers.c.topic,
) )
) )
@ -226,7 +227,6 @@ 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)