ratings-subquery-fix-2
All checks were successful
Deploy on push / deploy (push) Successful in 1m35s
All checks were successful
Deploy on push / deploy (push) Successful in 1m35s
This commit is contained in:
parent
8d47c02511
commit
c863dda81b
|
@ -72,15 +72,25 @@ def add_author_ratings(q):
|
||||||
ratings_subquery = (
|
ratings_subquery = (
|
||||||
select([
|
select([
|
||||||
Author.id,
|
Author.id,
|
||||||
func.count().filter(and_(
|
func.count().filter(
|
||||||
|
and_(
|
||||||
Reaction.created_by == Author.id,
|
Reaction.created_by == Author.id,
|
||||||
Reaction.kind == ReactionKind.COMMENT.value,
|
Reaction.kind == ReactionKind.COMMENT.value,
|
||||||
Reaction.deleted_at.is_(None),
|
Reaction.deleted_at.is_(None),
|
||||||
)).label('comments_count'),
|
)
|
||||||
func.sum(case((AuthorRating.plus == true(), 1), else_=0)).label('likes_count'),
|
).label('comments_count'),
|
||||||
func.sum(case((AuthorRating.plus != true(), 1), else_=0)).label('dislikes_count'),
|
func.sum(
|
||||||
func.sum(case((and_(Reaction.kind == ReactionKind.LIKE.value, Shout.authors.any(id=Author.id)), 1), else_=0)).label('shouts_likes'),
|
case((AuthorRating.plus == true(), 1), else_=0)
|
||||||
func.sum(case((and_(Reaction.kind == ReactionKind.DISLIKE.value, Shout.authors.any(id=Author.id)), 1), else_=0)).label('shouts_dislikes')
|
).label('likes_count'),
|
||||||
|
func.sum(
|
||||||
|
case((AuthorRating.plus != true(), 1), else_=0)
|
||||||
|
).label('dislikes_count'),
|
||||||
|
func.sum(
|
||||||
|
case((and_(Reaction.kind == ReactionKind.LIKE.value, Shout.authors.any(id=Author.id)), 1), else_=0)
|
||||||
|
).label('shouts_likes'),
|
||||||
|
func.sum(
|
||||||
|
case((and_(Reaction.kind == ReactionKind.DISLIKE.value, Shout.authors.any(id=Author.id)), 1), else_=0)
|
||||||
|
).label('shouts_dislikes')
|
||||||
])
|
])
|
||||||
.select_from(Author)
|
.select_from(Author)
|
||||||
.join(AuthorRating, AuthorRating.author == Author.id)
|
.join(AuthorRating, AuthorRating.author == Author.id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user