myrates-api-minor-fix3
This commit is contained in:
parent
773615e201
commit
6966d900fa
|
@ -52,25 +52,30 @@ async def get_my_rates_shouts(_, info, shouts):
|
||||||
if not author_id:
|
if not author_id:
|
||||||
return {"error": "Author not found"}
|
return {"error": "Author not found"}
|
||||||
|
|
||||||
# Подзапрос для реакций текущего пользователя
|
|
||||||
rated_query = (
|
|
||||||
select(Reaction.shout.label("shout_id"), Reaction.kind.label("my_rate"))
|
|
||||||
.where(
|
|
||||||
and_(
|
|
||||||
Reaction.shout.in_(shouts),
|
|
||||||
Reaction.reply_to.is_(None),
|
|
||||||
Reaction.created_by == author_id,
|
|
||||||
Reaction.deleted_at.is_(None),
|
|
||||||
Reaction.kind.in_([ReactionKind.LIKE.value, ReactionKind.DISLIKE.value]),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by(Reaction.shout, Reaction.created_at.desc())
|
|
||||||
.distinct(Reaction.shout)
|
|
||||||
.subquery()
|
|
||||||
)
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shouts_result = session.execute(rated_query).all()
|
# Используем прямой запрос без подзапросов
|
||||||
return [{"shout_id": row.shout_id, "my_rate": row.my_rate} for row in shouts_result]
|
result = session.execute(
|
||||||
|
select([
|
||||||
|
Reaction.shout.label("shout_id"),
|
||||||
|
Reaction.kind.label("my_rate")
|
||||||
|
]).where(
|
||||||
|
and_(
|
||||||
|
Reaction.shout.in_(shouts),
|
||||||
|
Reaction.reply_to.is_(None),
|
||||||
|
Reaction.created_by == author_id,
|
||||||
|
Reaction.deleted_at.is_(None),
|
||||||
|
Reaction.kind.in_([ReactionKind.LIKE.value, ReactionKind.DISLIKE.value])
|
||||||
|
)
|
||||||
|
).order_by(
|
||||||
|
Reaction.shout,
|
||||||
|
Reaction.created_at.desc()
|
||||||
|
).distinct(Reaction.shout)
|
||||||
|
).all()
|
||||||
|
|
||||||
|
return [
|
||||||
|
{"shout_id": row.shout_id, "my_rate": row.my_rate}
|
||||||
|
for row in result
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("rate_author")
|
@mutation.field("rate_author")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user