fmt
All checks were successful
Deploy on push / deploy (push) Successful in 7s

This commit is contained in:
2024-12-11 23:02:14 +03:00
parent c5d21c3554
commit fbcee18db1
6 changed files with 21 additions and 29 deletions

View File

@@ -49,35 +49,33 @@ async def get_my_rates_shouts(_, info, shouts):
"""
author_dict = info.context.get("author") if info.context else None
author_id = author_dict.get("id") if author_dict else None
if not author_id:
return []
with local_session() as session:
try:
stmt = (
select(
Reaction
).where(
select(Reaction)
.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])
Reaction.kind.in_([ReactionKind.LIKE.value, ReactionKind.DISLIKE.value]),
)
).order_by(
Reaction.shout,
Reaction.created_at.desc()
).distinct(Reaction.shout)
)
.order_by(Reaction.shout, Reaction.created_at.desc())
.distinct(Reaction.shout)
)
result = session.execute(stmt).all()
return [
{
"shout_id": row[0].shout, # Получаем shout_id из объекта Reaction
"my_rate": row[0].kind # Получаем kind (my_rate) из объекта Reaction
"my_rate": row[0].kind, # Получаем kind (my_rate) из объекта Reaction
}
for row in result
]

View File

@@ -161,9 +161,9 @@ def query_with_stat(info):
)
.filter(Reaction.reply_to.is_(None))
.label("rating"),
func.max(Reaction.created_at).filter(Reaction.kind == ReactionKind.COMMENT.value).label(
"last_commented_at"
),
func.max(Reaction.created_at)
.filter(Reaction.kind == ReactionKind.COMMENT.value)
.label("last_commented_at"),
)
.where(Reaction.deleted_at.is_(None))
.group_by(Reaction.shout)
@@ -177,7 +177,7 @@ def query_with_stat(info):
"rating",
func.coalesce(stats_subquery.c.rating, 0),
"last_commented_at",
func.coalesce(stats_subquery.c.last_commented_at, 0)
func.coalesce(stats_subquery.c.last_commented_at, 0),
).label("stat")
)