cache-reimplement-2
All checks were successful
Deploy on push / deploy (push) Successful in 1m4s

This commit is contained in:
2024-05-21 01:40:57 +03:00
parent 3742528e3a
commit 4c1fbf64a2
13 changed files with 292 additions and 326 deletions

View File

@@ -56,10 +56,9 @@ def get_topic_shouts_stat(topic_id: int):
return result[0] if result else 0
def get_topic_authors_stat(topic_id: int):
# authors
q = (
select(func.count(distinct(ShoutAuthor.author)))
def get_topic_authors_query(topic_id):
return (
select(ShoutAuthor.author)
.select_from(join(ShoutTopic, Shout, ShoutTopic.shout == Shout.id))
.join(ShoutAuthor, ShoutAuthor.shout == Shout.id)
.filter(
@@ -70,8 +69,18 @@ def get_topic_authors_stat(topic_id: int):
)
)
)
result = local_session().execute(q).first()
return result[0] if result else 0
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
def get_topic_followers_stat(topic_id: int):