This commit is contained in:
parent
4daf746976
commit
fab57469d3
|
@ -381,23 +381,28 @@ async def load_shouts_random_top(_, _info, options):
|
||||||
aliased_reaction = aliased(Reaction)
|
aliased_reaction = aliased(Reaction)
|
||||||
|
|
||||||
subquery = (
|
subquery = (
|
||||||
select(Shout.id).outerjoin(aliased_reaction).where(Shout.deleted_at.is_(None))
|
select(Shout.id)
|
||||||
|
.outerjoin(aliased_reaction)
|
||||||
|
.where(and_(Shout.deleted_at.is_(None), Shout.layout.is_not(None)))
|
||||||
)
|
)
|
||||||
|
|
||||||
subquery = apply_filters(subquery, options.get('filters', {}))
|
subquery = apply_filters(subquery, options.get('filters', {}))
|
||||||
|
|
||||||
subquery = subquery.group_by(Shout.id).order_by(
|
subquery = subquery.group_by(Shout.id).order_by(
|
||||||
desc(
|
desc(
|
||||||
func.sum(
|
func.sum(
|
||||||
case(
|
case(
|
||||||
(Reaction.kind == str(ReactionKind.LIKE.value), 1),
|
# do not count comments' reactions
|
||||||
(Reaction.kind == str(ReactionKind.DISLIKE.value), -1),
|
(aliased_reaction.replyTo.is_not(None), 0),
|
||||||
|
(aliased_reaction.kind == ReactionKind.LIKE.value, 1),
|
||||||
|
(aliased_reaction.kind == ReactionKind.DISLIKE.value, -1),
|
||||||
else_=0,
|
else_=0,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
random_limit = options.get('random_limit')
|
random_limit = options.get('random_limit', 100)
|
||||||
if random_limit:
|
if random_limit:
|
||||||
subquery = subquery.limit(random_limit)
|
subquery = subquery.limit(random_limit)
|
||||||
|
|
||||||
|
@ -406,7 +411,7 @@ async def load_shouts_random_top(_, _info, options):
|
||||||
.options(joinedload(Shout.authors), joinedload(Shout.topics))
|
.options(joinedload(Shout.authors), joinedload(Shout.topics))
|
||||||
.where(Shout.id.in_(subquery))
|
.where(Shout.id.in_(subquery))
|
||||||
)
|
)
|
||||||
aliased_reaction = aliased(Reaction)
|
|
||||||
q = add_reaction_stat_columns(q, aliased_reaction)
|
q = add_reaction_stat_columns(q, aliased_reaction)
|
||||||
|
|
||||||
limit = options.get('limit', 10)
|
limit = options.get('limit', 10)
|
||||||
|
@ -417,6 +422,7 @@ async def load_shouts_random_top(_, _info, options):
|
||||||
return shouts
|
return shouts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@query.field('load_shouts_random_topic')
|
@query.field('load_shouts_random_topic')
|
||||||
async def load_shouts_random_topic(_, info, limit: int = 10):
|
async def load_shouts_random_topic(_, info, limit: int = 10):
|
||||||
[topic] = get_topics_random(None, None, 1)
|
[topic] = get_topics_random(None, None, 1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user