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,11 +50,13 @@ 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:
|
||||
# Используем прямой запрос без подзапросов
|
||||
try:
|
||||
result = session.execute(
|
||||
select([
|
||||
Reaction.shout.label("shout_id"),
|
||||
|
@ -76,6 +79,10 @@ async def get_my_rates_shouts(_, info, shouts):
|
|||
{"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