This commit is contained in:
parent
3247a3674f
commit
8ad00f0fa5
|
@ -43,21 +43,28 @@ def query_with_stat(info):
|
||||||
stats_subquery = (
|
stats_subquery = (
|
||||||
select(
|
select(
|
||||||
Reaction.shout,
|
Reaction.shout,
|
||||||
func.count(case([(Reaction.kind == ReactionKind.COMMENT.value, 1)], else_=None)).label(
|
func.count(
|
||||||
"comments_count"
|
case(
|
||||||
),
|
(Reaction.kind == ReactionKind.COMMENT.value, 1),
|
||||||
|
else_=None,
|
||||||
|
)
|
||||||
|
).label("comments_count"),
|
||||||
|
func.coalesce(
|
||||||
func.sum(
|
func.sum(
|
||||||
case(
|
case(
|
||||||
[
|
|
||||||
(Reaction.kind == ReactionKind.LIKE.value, 1),
|
(Reaction.kind == ReactionKind.LIKE.value, 1),
|
||||||
(Reaction.kind == ReactionKind.DISLIKE.value, -1),
|
(Reaction.kind == ReactionKind.DISLIKE.value, -1),
|
||||||
],
|
|
||||||
else_=0,
|
else_=0,
|
||||||
)
|
)
|
||||||
).label("rating"),
|
|
||||||
func.max(case([(Reaction.reply_to.is_(None), Reaction.created_at)], else_=None)).label(
|
|
||||||
"last_reacted_at"
|
|
||||||
),
|
),
|
||||||
|
0,
|
||||||
|
).label("rating"),
|
||||||
|
func.max(
|
||||||
|
case(
|
||||||
|
(Reaction.reply_to.is_(None), Reaction.created_at),
|
||||||
|
else_=None,
|
||||||
|
)
|
||||||
|
).label("last_reacted_at"),
|
||||||
)
|
)
|
||||||
.where(Reaction.deleted_at.is_(None))
|
.where(Reaction.deleted_at.is_(None))
|
||||||
.group_by(Reaction.shout)
|
.group_by(Reaction.shout)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user