From 6966d900fa8819ae9bdbedf3d6786ed69e3c4736 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 18 Nov 2024 22:10:25 +0300 Subject: [PATCH] myrates-api-minor-fix3 --- resolvers/rating.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/resolvers/rating.py b/resolvers/rating.py index 7a751f02..876a1340 100644 --- a/resolvers/rating.py +++ b/resolvers/rating.py @@ -52,25 +52,30 @@ async def get_my_rates_shouts(_, info, shouts): if not author_id: 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: - 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")