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.auth import login_required
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
from services.schema import mutation, query
|
from services.schema import mutation, query
|
||||||
|
from utils.logger import root_logger as logger
|
||||||
|
|
||||||
|
|
||||||
@query.field("get_my_rates_comments")
|
@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_dict = info.context.get("author") if info.context else None
|
||||||
author_id = author_dict.get("id") if author_dict else None
|
author_id = author_dict.get("id") if author_dict else None
|
||||||
|
|
||||||
|
# Возвращаем пустой список вместо None/error
|
||||||
if not author_id:
|
if not author_id:
|
||||||
return {"error": "Author not found"}
|
return []
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
# Используем прямой запрос без подзапросов
|
try:
|
||||||
result = session.execute(
|
result = session.execute(
|
||||||
select([
|
select([
|
||||||
Reaction.shout.label("shout_id"),
|
Reaction.shout.label("shout_id"),
|
||||||
Reaction.kind.label("my_rate")
|
Reaction.kind.label("my_rate")
|
||||||
]).where(
|
]).where(
|
||||||
and_(
|
and_(
|
||||||
Reaction.shout.in_(shouts),
|
Reaction.shout.in_(shouts),
|
||||||
Reaction.reply_to.is_(None),
|
Reaction.reply_to.is_(None),
|
||||||
Reaction.created_by == author_id,
|
Reaction.created_by == author_id,
|
||||||
Reaction.deleted_at.is_(None),
|
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(
|
).order_by(
|
||||||
Reaction.shout,
|
Reaction.shout,
|
||||||
Reaction.created_at.desc()
|
Reaction.created_at.desc()
|
||||||
).distinct(Reaction.shout)
|
).distinct(Reaction.shout)
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{"shout_id": row.shout_id, "my_rate": row.my_rate}
|
{"shout_id": row.shout_id, "my_rate": row.my_rate}
|
||||||
for row in result
|
for row in result
|
||||||
]
|
]
|
||||||
|
except Exception as e:
|
||||||
|
# В случае ошибки тоже возвращаем пустой список
|
||||||
|
logger.error(f"Error in get_my_rates_shouts: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("rate_author")
|
@mutation.field("rate_author")
|
||||||
|
|
|
@ -239,11 +239,6 @@ def get_shouts_with_links(info, q, limit=20, offset=0):
|
||||||
shout = None
|
shout = None
|
||||||
if hasattr(row, "Shout"):
|
if hasattr(row, "Shout"):
|
||||||
shout = row.Shout
|
shout = row.Shout
|
||||||
else:
|
|
||||||
if not row == "stat":
|
|
||||||
logger.warning(f"Строка {idx} не содержит атрибута 'Shout': {row}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
if shout:
|
if shout:
|
||||||
shout_id = int(f"{shout.id}")
|
shout_id = int(f"{shout.id}")
|
||||||
shout_dict = shout.dict()
|
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)}")
|
logger.warning(f"Строка {idx} - неизвестный тип stat: {type(row.stat)}")
|
||||||
viewed = ViewedStorage.get_shout(shout_id=shout_id) or 0
|
viewed = ViewedStorage.get_shout(shout_id=shout_id) or 0
|
||||||
shout_dict["stat"] = {**stat, "viewed": viewed, "commented": stat.get("comments_count", 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"):
|
if has_field(info, "main_topic") and hasattr(row, "main_topic"):
|
||||||
shout_dict["main_topic"] = (
|
shout_dict["main_topic"] = (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user