postfixing-reimplemented-cache
All checks were successful
Deploy on push / deploy (push) Successful in 27s

This commit is contained in:
2024-05-21 02:01:18 +03:00
parent 4c1fbf64a2
commit 1592065a8c
6 changed files with 29 additions and 25 deletions

View File

@@ -56,9 +56,9 @@ def get_topic_shouts_stat(topic_id: int):
return result[0] if result else 0
def get_topic_authors_query(topic_id):
return (
select(ShoutAuthor.author)
def get_topic_authors_stat(topic_id: int):
count_query = (
select(func.count(distinct(ShoutAuthor.author)))
.select_from(join(ShoutTopic, Shout, ShoutTopic.shout == Shout.id))
.join(ShoutAuthor, ShoutAuthor.shout == Shout.id)
.filter(
@@ -70,14 +70,6 @@ def get_topic_authors_query(topic_id):
)
)
def get_topic_authors_stat(topic_id: int):
# authors query
topic_authors_query = get_topic_authors_query(topic_id)
# Оборачиваем запрос в другой запрос, чтобы посчитать уникальных авторов
count_query = select(func.count(distinct(topic_authors_query.subquery().c.author)))
# Выполняем запрос и получаем результат
result = local_session().execute(count_query).scalar()
return result if result is not None else 0