counters-fix
All checks were successful
Deploy on push / deploy (push) Successful in 23s

This commit is contained in:
Untone 2024-04-25 11:47:13 +03:00
parent c4148254ed
commit e68196ce0b

View File

@ -58,8 +58,8 @@ def get_topic_shouts_stat(topic_id: int):
) )
) )
) )
[shouts_stat] = local_session().execute(q) result = local_session().execute(q).first()
return shouts_stat or 0 return result[0] if result else 0
def get_topic_authors_stat(topic_id: int): def get_topic_authors_stat(topic_id: int):
@ -76,8 +76,8 @@ def get_topic_authors_stat(topic_id: int):
) )
) )
) )
[authors_stat] = local_session().execute(q) result = local_session().execute(q).first()
return authors_stat or 0 return result[0] if result else 0
def get_topic_followers_stat(topic_id: int): def get_topic_followers_stat(topic_id: int):
@ -85,9 +85,8 @@ def get_topic_followers_stat(topic_id: int):
q = select(func.count(distinct(aliased_followers.follower))).filter( q = select(func.count(distinct(aliased_followers.follower))).filter(
aliased_followers.topic == topic_id aliased_followers.topic == topic_id
) )
with local_session() as session: result = local_session().execute(q).first()
[followers_stat] = session.execute(q) return result[0] if result else 0
return followers_stat or 0
def get_topic_comments_stat(topic_id: int): def get_topic_comments_stat(topic_id: int):
@ -113,18 +112,17 @@ def get_topic_comments_stat(topic_id: int):
ShoutTopic.topic == topic_id ShoutTopic.topic == topic_id
) )
q = q.outerjoin(sub_comments, ShoutTopic.shout == sub_comments.c.shout_id) q = q.outerjoin(sub_comments, ShoutTopic.shout == sub_comments.c.shout_id)
[comments_stat] = local_session().execute(q)
return comments_stat or 0
result = local_session().execute(q).first()
return result[0] if result else 0
def get_author_shouts_stat(author_id: int): def get_author_shouts_stat(author_id: int):
aliased_shout_author = aliased(ShoutAuthor) aliased_shout_author = aliased(ShoutAuthor)
q = select(func.count(distinct(aliased_shout_author.shout))).filter( q = select(func.count(distinct(aliased_shout_author.shout))).filter(
aliased_shout_author.author == author_id aliased_shout_author.author == author_id
) )
with local_session() as session: result = local_session().execute(q).first()
[shouts_stat] = session.execute(q) return result[0] if result else 0
return shouts_stat or 0
def get_author_authors_stat(author_id: int): def get_author_authors_stat(author_id: int):
@ -135,9 +133,8 @@ def get_author_authors_stat(author_id: int):
aliased_authors.author != author_id, aliased_authors.author != author_id,
) )
) )
with local_session() as session: result = local_session().execute(q).first()
[authors_stat] = session.execute(q) return result[0] if result else 0
return authors_stat or 0
def get_author_followers_stat(author_id: int): def get_author_followers_stat(author_id: int):
@ -145,9 +142,8 @@ def get_author_followers_stat(author_id: int):
q = select(func.count(distinct(aliased_followers.follower))).filter( q = select(func.count(distinct(aliased_followers.follower))).filter(
aliased_followers.author == author_id aliased_followers.author == author_id
) )
with local_session() as session: result = local_session().execute(q).first()
[followers_stat] = session.execute(q) return result[0] if result else 0
return followers_stat or 0
def get_author_comments_stat(author_id: int): def get_author_comments_stat(author_id: int):
@ -168,9 +164,9 @@ def get_author_comments_stat(author_id: int):
.subquery() .subquery()
) )
q = select(sub_comments.c.comments_count).filter(sub_comments.c.id == author_id) q = select(sub_comments.c.comments_count).filter(sub_comments.c.id == author_id)
with local_session() as session:
[comments_stat] = session.execute(q) result = local_session().execute(q).first()
return comments_stat or 0 return result[0] if result else 0
def get_with_stat(q): def get_with_stat(q):