From 8432a00691855e22f41cd72332978146a8860399 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 21 Jan 2025 18:28:03 +0300 Subject: [PATCH] create-shout-fix2 --- resolvers/editor.py | 28 ++++++++++++++-------------- resolvers/reader.py | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/resolvers/editor.py b/resolvers/editor.py index 7dd6f2db..cd63b360 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -110,16 +110,16 @@ async def create_shout(_, info, inp): author_id = int(author_id) current_time = int(time.time()) slug = inp.get("slug") or f"draft-{current_time}" - + logger.info(f"Creating shout with slug: {slug}") - - # Создаем объект Shout напрямую, без промежуточного словаря - new_shout = Shout({ - **inp, - "slug": slug, - "created_by": author_id, - "created_at": current_time - }) + + # Правильно: + new_shout = Shout( + **inp, # распаковываем входные данные + slug=slug, # явно указываем именованные аргументы + created_by=author_id, + created_at=current_time, + ) # Check for duplicate slug logger.debug(f"Checking for existing slug: {slug}") @@ -195,7 +195,7 @@ async def create_shout(_, info, inp): try: author = session.query(Author).filter(Author.id == author_id).first() if author and author.stat: - author.stat["shouts"] = (author.stat.get("shouts", 0) + 1) + author.stat["shouts"] = author.stat.get("shouts", 0) + 1 session.add(author) session.commit() await cache_author(author.dict()) @@ -336,7 +336,7 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False): # Инвалидация кэша после обновления try: logger.info("Invalidating cache after shout update") - + cache_keys = [ "feed", # лента f"author_{author_id}", # публикации автора @@ -348,7 +348,7 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False): for topic in shout_by_id.topics: cache_keys.append(f"topic_{topic.id}") cache_keys.append(f"topic_shouts_{topic.id}") - + # Добавляем ключи для новых тем (если есть в shout_input) if shout_input.get("topics"): for topic in shout_input["topics"]: @@ -357,13 +357,13 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False): cache_keys.append(f"topic_shouts_{topic.id}") await invalidate_shouts_cache(cache_keys) - + # Обновляем кэш тем и авторов for topic in shout_by_id.topics: await cache_by_id(Topic, topic.id, cache_topic) for author in shout_by_id.authors: await cache_author(author.dict()) - + logger.info("Cache invalidated successfully") except Exception as cache_error: logger.warning(f"Cache invalidation error: {cache_error}", exc_info=True) diff --git a/resolvers/reader.py b/resolvers/reader.py index 310b44ca..0f5beaf9 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -343,7 +343,7 @@ def apply_sorting(q, options): async def load_shouts_by(_, info: GraphQLResolveInfo, options): """ Загрузка публикаций с фильтрацией, сортировкой и пагинацией. - + :param _: Корневой объект запроса (не используется) :param info: Информация о контексте GraphQL :param options: Опции фильтрации и сортировки @@ -351,7 +351,7 @@ async def load_shouts_by(_, info: GraphQLResolveInfo, options): """ # Базовый запрос со статистикой q = query_with_stat(info) - + # Применяем остальные опции фильтрации q, limit, offset = apply_options(q, options)