unrated shouts query fix (#112)
Co-authored-by: Igor Lobanov <igor.lobanov@onetwotrip.com>
This commit is contained in:
parent
e23e379102
commit
ff834987d4
|
@ -257,6 +257,9 @@ async def load_random_top_shouts(_, info, params):
|
||||||
@query.field("loadUnratedShouts")
|
@query.field("loadUnratedShouts")
|
||||||
async def load_unrated_shouts(_, info, limit):
|
async def load_unrated_shouts(_, info, limit):
|
||||||
auth: AuthCredentials = info.context["request"].auth
|
auth: AuthCredentials = info.context["request"].auth
|
||||||
|
user_id = auth.user_id
|
||||||
|
|
||||||
|
aliased_reaction = aliased(Reaction)
|
||||||
|
|
||||||
q = (
|
q = (
|
||||||
select(Shout)
|
select(Shout)
|
||||||
|
@ -272,22 +275,36 @@ async def load_unrated_shouts(_, info, limit):
|
||||||
Reaction.kind.in_([ReactionKind.LIKE, ReactionKind.DISLIKE]),
|
Reaction.kind.in_([ReactionKind.LIKE, ReactionKind.DISLIKE]),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.where(
|
)
|
||||||
|
|
||||||
|
if user_id:
|
||||||
|
q = q.outerjoin(
|
||||||
|
aliased_reaction,
|
||||||
and_(
|
and_(
|
||||||
Shout.deletedAt.is_(None),
|
aliased_reaction.shout == Shout.id,
|
||||||
Shout.layout.is_not(None),
|
aliased_reaction.replyTo.is_(None),
|
||||||
Shout.createdAt >= (datetime.now() - timedelta(days=14)).date(),
|
aliased_reaction.kind.in_([ReactionKind.LIKE, ReactionKind.DISLIKE]),
|
||||||
)
|
aliased_reaction.createdBy == user_id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
q = q.where(
|
||||||
|
and_(
|
||||||
|
Shout.deletedAt.is_(None),
|
||||||
|
Shout.layout.is_not(None),
|
||||||
|
Shout.createdAt >= (datetime.now() - timedelta(days=14)).date(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
user_id = auth.user_id
|
|
||||||
if user_id:
|
if user_id:
|
||||||
q = q.where(Reaction.createdBy != user_id)
|
q = q.where(Shout.createdBy != user_id)
|
||||||
|
|
||||||
# 3 or fewer votes is 0, 1, 2 or 3 votes (null, reaction id1, reaction id2, reaction id3)
|
# 3 or fewer votes is 0, 1, 2 or 3 votes (null, reaction id1, reaction id2, reaction id3)
|
||||||
q = q.having(func.count(distinct(Reaction.id)) <= 4)
|
q = q.having(func.count(distinct(Reaction.id)) <= 4)
|
||||||
|
|
||||||
|
if user_id:
|
||||||
|
q = q.having(func.count(distinct(aliased_reaction.id)) == 0)
|
||||||
|
|
||||||
q = add_stat_columns(q)
|
q = add_stat_columns(q)
|
||||||
|
|
||||||
q = q.group_by(Shout.id).order_by(func.random()).limit(limit)
|
q = q.group_by(Shout.id).order_by(func.random()).limit(limit)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user