circular-fix
Some checks failed
Deploy on push / deploy (push) Failing after 17s

This commit is contained in:
2025-08-17 16:33:54 +03:00
parent bc8447a444
commit e78e12eeee
65 changed files with 3304 additions and 1051 deletions

View File

@@ -1,5 +1,5 @@
import time
from typing import Any
from typing import Any, List
import orjson
from graphql import GraphQLResolveInfo
@@ -8,6 +8,12 @@ from sqlalchemy.orm import joinedload
from sqlalchemy.sql.functions import coalesce
from auth.orm import Author
from cache.cache import (
cache_author,
cache_topic,
invalidate_shout_related_cache,
invalidate_shouts_cache,
)
from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.topic import Topic
from resolvers.follower import follow
@@ -383,16 +389,15 @@ def patch_topics(session: Any, shout: Any, topics_input: list[Any]) -> None:
# @mutation.field("update_shout")
# @login_required
async def update_shout(
_: None, info: GraphQLResolveInfo, shout_id: int, shout_input: dict | None = None, *, publish: bool = False
_: None,
info: GraphQLResolveInfo,
shout_id: int,
title: str | None = None,
body: str | None = None,
topics: List[str] | None = None,
collections: List[int] | None = None,
publish: bool = False,
) -> CommonResult:
# Поздние импорты для избежания циклических зависимостей
from cache.cache import (
cache_author,
cache_topic,
invalidate_shout_related_cache,
invalidate_shouts_cache,
)
"""Update an existing shout with optional publishing"""
logger.info(f"update_shout called with shout_id={shout_id}, publish={publish}")
@@ -403,12 +408,9 @@ async def update_shout(
return CommonResult(error="unauthorized", shout=None)
logger.info(f"Starting update_shout with id={shout_id}, publish={publish}")
logger.debug(f"Full shout_input: {shout_input}") # DraftInput
roles = info.context.get("roles", [])
current_time = int(time.time())
shout_input = shout_input or {}
shout_id = shout_id or shout_input.get("id", shout_id)
slug = shout_input.get("slug")
slug = title # Используем title как slug если он передан
try:
with local_session() as session:
@@ -442,17 +444,18 @@ async def update_shout(
c += 1
same_slug_shout.slug = f"{slug}-{c}" # type: ignore[assignment]
same_slug_shout = session.query(Shout).where(Shout.slug == slug).first()
shout_input["slug"] = slug
shout_by_id.slug = slug
logger.info(f"shout#{shout_id} slug patched")
if filter(lambda x: x.id == author_id, list(shout_by_id.authors)) or "editor" in roles:
logger.info(f"Author #{author_id} has permission to edit shout#{shout_id}")
# topics patch
topics_input = shout_input.get("topics")
if topics_input:
logger.info(f"Received topics_input for shout#{shout_id}: {topics_input}")
if topics:
logger.info(f"Received topics for shout#{shout_id}: {topics}")
try:
# Преобразуем topics в формат для patch_topics
topics_input = [{"id": int(t)} for t in topics if t.isdigit()]
patch_topics(session, shout_by_id, topics_input)
logger.info(f"Successfully patched topics for shout#{shout_id}")
@@ -463,17 +466,16 @@ async def update_shout(
logger.error(f"Error patching topics: {e}", exc_info=True)
return CommonResult(error=f"Failed to update topics: {e!s}", shout=None)
del shout_input["topics"]
for tpc in topics_input:
await cache_by_id(Topic, tpc["id"], cache_topic)
else:
logger.warning(f"No topics_input received for shout#{shout_id}")
logger.warning(f"No topics received for shout#{shout_id}")
# main topic
main_topic = shout_input.get("main_topic")
if main_topic:
logger.info(f"Updating main topic for shout#{shout_id} to {main_topic}")
patch_main_topic(session, main_topic, shout_by_id)
# Обновляем title и body если переданы
if title:
shout_by_id.title = title
if body:
shout_by_id.body = body
shout_by_id.updated_at = current_time # type: ignore[assignment]
if publish:
@@ -497,8 +499,8 @@ async def update_shout(
logger.info("Author link already exists")
# Логируем финальное состояние перед сохранением
logger.info(f"Final shout_input for update: {shout_input}")
Shout.update(shout_by_id, shout_input)
logger.info(f"Final shout_input for update: {shout_by_id.dict()}")
Shout.update(shout_by_id, shout_by_id.dict())
session.add(shout_by_id)
try:
@@ -572,11 +574,6 @@ async def update_shout(
# @mutation.field("delete_shout")
# @login_required
async def delete_shout(_: None, info: GraphQLResolveInfo, shout_id: int) -> CommonResult:
# Поздние импорты для избежания циклических зависимостей
from cache.cache import (
invalidate_shout_related_cache,
)
"""Delete a shout (mark as deleted)"""
author_dict = info.context.get("author", {})
if not author_dict:
@@ -667,12 +664,6 @@ async def unpublish_shout(_: None, info: GraphQLResolveInfo, shout_id: int) -> C
"""
Unpublish a shout by setting published_at to NULL
"""
# Поздние импорты для избежания циклических зависимостей
from cache.cache import (
invalidate_shout_related_cache,
invalidate_shouts_cache,
)
author_dict = info.context.get("author", {})
author_id = author_dict.get("id")
roles = info.context.get("roles", [])