all-authors-fix-2
This commit is contained in:
parent
1cdf286594
commit
6c607732a8
|
@ -18,47 +18,46 @@ from resolvers.reaction import reacted_shouts_updates as followed_reactions
|
||||||
|
|
||||||
|
|
||||||
def add_author_stat_columns(q):
|
def add_author_stat_columns(q):
|
||||||
followers_table = aliased(AuthorFollower)
|
|
||||||
# followings_table = aliased(AuthorFollower)
|
|
||||||
shout_author_aliased = aliased(ShoutAuthor)
|
shout_author_aliased = aliased(ShoutAuthor)
|
||||||
# reaction_aliased = aliased(Reaction)
|
|
||||||
|
|
||||||
q = q.outerjoin(shout_author_aliased).add_columns(
|
q = q.outerjoin(shout_author_aliased).add_columns(
|
||||||
func.count(distinct(shout_author_aliased.shout))
|
func.count(distinct(shout_author_aliased.shout)).label("shouts_stat")
|
||||||
.label("shouts_stat")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
followers_table = aliased(AuthorFollower)
|
||||||
q = q.outerjoin(followers_table, followers_table.author == Author.id).add_columns(
|
q = q.outerjoin(followers_table, followers_table.author == Author.id).add_columns(
|
||||||
func.count(distinct(followers_table.follower))
|
func.count(distinct(followers_table.follower)).label("followers_stat")
|
||||||
.label("followers_stat")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
q = q.add_columns(literal(0).label("rating_stat"))
|
followings_table = aliased(AuthorFollower)
|
||||||
# TODO: check version 1
|
q = q.outerjoin(followings_table, followings_table.follower == Author.id).add_columns(
|
||||||
# q = q.outerjoin(user_rating_aliased, user_rating_aliased.user == User.id).add_columns(
|
func.count(distinct(followers_table.author)).label("followings_stat")
|
||||||
# func.sum(user_rating_aliased.value).label('rating_stat')
|
)
|
||||||
# )
|
|
||||||
# TODO: check version 2
|
rating_aliased = aliased(Reaction)
|
||||||
# q = (
|
# q = q.add_columns(literal(0).label("rating_stat"))
|
||||||
# q.outerjoin(reaction_aliased, reaction_aliased.shout == shout_author_aliased.shout)
|
q = (
|
||||||
# .add_columns(
|
q.outerjoin(rating_aliased, rating_aliased.shout == shout_author_aliased.shout)
|
||||||
# func.coalesce(func.sum(case(
|
.add_columns(
|
||||||
# (and_(
|
func.coalesce(func.sum(case(
|
||||||
# reaction_aliased.kind == ReactionKind.LIKE.value,
|
(and_(
|
||||||
# reaction_aliased.reply_to.is_(None)
|
rating_aliased.kind == ReactionKind.LIKE.value,
|
||||||
# ), 1),
|
rating_aliased.reply_to.is_(None)
|
||||||
# (and_(
|
), 1),
|
||||||
# reaction_aliased.kind == ReactionKind.DISLIKE.value,
|
(and_(
|
||||||
# reaction_aliased.reply_to.is_(None)
|
rating_aliased.kind == ReactionKind.DISLIKE.value,
|
||||||
# ), -1),
|
rating_aliased.reply_to.is_(None)
|
||||||
# else_=0
|
), -1),
|
||||||
# )), 0)
|
else_=0
|
||||||
# .label("rating_stat")
|
)), 0)
|
||||||
# )
|
.label("rating_stat")
|
||||||
# )
|
)
|
||||||
|
)
|
||||||
|
|
||||||
q = q.add_columns(literal(0).label("commented_stat"))
|
q = q.add_columns(literal(0).label("commented_stat"))
|
||||||
|
|
||||||
|
# WARNING: too high cpu cost
|
||||||
|
|
||||||
# TODO: check version 1
|
# TODO: check version 1
|
||||||
# q = q.outerjoin(
|
# q = q.outerjoin(
|
||||||
# Reaction, and_(Reaction.createdBy == User.id, Reaction.body.is_not(None))
|
# Reaction, and_(Reaction.createdBy == User.id, Reaction.body.is_not(None))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user