This commit is contained in:
parent
56f1506450
commit
71db929fa4
|
@ -28,7 +28,7 @@ def add_reaction_stat_columns(q, aliased_reaction):
|
||||||
# Присоединение реакций и добавление статистических колонок
|
# Присоединение реакций и добавление статистических колонок
|
||||||
q = q.outerjoin(aliased_reaction, aliased_reaction.deleted_at.is_(None)).add_columns(
|
q = q.outerjoin(aliased_reaction, aliased_reaction.deleted_at.is_(None)).add_columns(
|
||||||
# Подсчет комментариев
|
# Подсчет комментариев
|
||||||
func.count(case((aliased_reaction.body.is_not(None), 1), else_=0)).label("comments_stat"),
|
func.count().filter(aliased_reaction.kind == ReactionKind.COMMENT.value).label("comments_stat"),
|
||||||
# Вычисление рейтинга как разница между лайками и дизлайками
|
# Вычисление рейтинга как разница между лайками и дизлайками
|
||||||
func.sum(
|
func.sum(
|
||||||
case(
|
case(
|
||||||
|
|
|
@ -83,7 +83,7 @@ def query_shouts(slug=None):
|
||||||
q = (
|
q = (
|
||||||
select(
|
select(
|
||||||
Shout,
|
Shout,
|
||||||
func.count(case((aliased_reaction.body.is_not(None), 1))).label("comments_stat"),
|
func.count().filter(aliased_reaction.kind == ReactionKind.COMMENT.value).label("comments_stat"),
|
||||||
func.count(distinct(ShoutReactionsFollower.follower)).label("followers_stat"),
|
func.count(distinct(ShoutReactionsFollower.follower)).label("followers_stat"),
|
||||||
func.sum(
|
func.sum(
|
||||||
case(
|
case(
|
||||||
|
@ -178,7 +178,7 @@ def get_shouts_with_stats(q, limit, offset=0, author_id=None):
|
||||||
shout.topics = parse_aggregated_string(topics, Topic)
|
shout.topics = parse_aggregated_string(topics, Topic)
|
||||||
shout.stat = {
|
shout.stat = {
|
||||||
"viewed": ViewedStorage.get_shout(shout.id),
|
"viewed": ViewedStorage.get_shout(shout.id),
|
||||||
"followers": followers_stat or 0,
|
"followed": followers_stat or 0,
|
||||||
"rating": rating_stat or 0,
|
"rating": rating_stat or 0,
|
||||||
"commented": comments_stat or 0,
|
"commented": comments_stat or 0,
|
||||||
"last_reacted_at": last_reacted_at,
|
"last_reacted_at": last_reacted_at,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user