This commit is contained in:
parent
2fec47d363
commit
cf88c165ee
|
@ -7,6 +7,7 @@ from orm.shout import Shout
|
|||
from services.auth import login_required
|
||||
from services.db import local_session
|
||||
from services.schema import mutation, query
|
||||
from utils.logger import root_logger as logger
|
||||
|
||||
|
||||
@query.field("get_my_rates_comments")
|
||||
|
@ -49,33 +50,39 @@ 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
|
||||
|
||||
# Возвращаем пустой список вместо None/error
|
||||
if not author_id:
|
||||
return {"error": "Author not found"}
|
||||
return []
|
||||
|
||||
with local_session() as session:
|
||||
# Используем прямой запрос без подзапросов
|
||||
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()
|
||||
try:
|
||||
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
|
||||
]
|
||||
return [
|
||||
{"shout_id": row.shout_id, "my_rate": row.my_rate}
|
||||
for row in result
|
||||
]
|
||||
except Exception as e:
|
||||
# В случае ошибки тоже возвращаем пустой список
|
||||
logger.error(f"Error in get_my_rates_shouts: {e}")
|
||||
return []
|
||||
|
||||
|
||||
@mutation.field("rate_author")
|
||||
|
|
|
@ -239,11 +239,6 @@ def get_shouts_with_links(info, q, limit=20, offset=0):
|
|||
shout = None
|
||||
if hasattr(row, "Shout"):
|
||||
shout = row.Shout
|
||||
else:
|
||||
if not row == "stat":
|
||||
logger.warning(f"Строка {idx} не содержит атрибута 'Shout': {row}")
|
||||
continue
|
||||
|
||||
if shout:
|
||||
shout_id = int(f"{shout.id}")
|
||||
shout_dict = shout.dict()
|
||||
|
@ -268,8 +263,6 @@ def get_shouts_with_links(info, q, limit=20, offset=0):
|
|||
logger.warning(f"Строка {idx} - неизвестный тип stat: {type(row.stat)}")
|
||||
viewed = ViewedStorage.get_shout(shout_id=shout_id) or 0
|
||||
shout_dict["stat"] = {**stat, "viewed": viewed, "commented": stat.get("comments_count", 0)}
|
||||
else:
|
||||
logger.warning(f"Строка {idx} не содержит атрибута 'stat'")
|
||||
|
||||
if has_field(info, "main_topic") and hasattr(row, "main_topic"):
|
||||
shout_dict["main_topic"] = (
|
||||
|
|
Loading…
Reference in New Issue
Block a user