From b73cce5431f4b4c517ee45ea2882c898421dde19 Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 18 May 2024 17:41:04 +0300 Subject: [PATCH] create-reaction-fix-2 --- resolvers/reaction.py | 12 ++++++------ services/triggers.py | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/resolvers/reaction.py b/resolvers/reaction.py index 9e30f519..0b369cd6 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -155,7 +155,6 @@ async def _create_reaction(session, shout, author_id: int, reaction): await update_author_stat(author_id) rdict["shout"] = shout.dict() - rdict["created_by"] = author_id rdict["stat"] = {"commented": 0, "reacted": 0, "rating": 0} # notifications call @@ -203,12 +202,13 @@ def prepare_new_rating(reaction: dict, shout_id: int, session, author_id: int): @mutation.field("create_reaction") @login_required async def create_reaction(_, info, reaction): - logger.debug(f"{info.context} for {reaction}") + # logger.debug(f"{info.context} for {reaction}") info.context.get("user_id") - author_id = info.context.get("author", {}).get("id") - shout_id = reaction.get("shout") - if not author_id: + author_dict = info.context.get("author", {}) + if not isinstance(author_dict, dict): return {"error": "Unauthorized"} + author_id = author_dict.get("id") + shout_id = reaction.get("shout") if not shout_id: return {"error": "Shout ID is required to create a reaction."} @@ -235,7 +235,7 @@ async def create_reaction(_, info, reaction): rdict = await _create_reaction(session, shout, author_id, reaction) # TODO: call recount ratings periodically - + rdict["created_by"] = author_dict return {"reaction": rdict} except Exception as e: import traceback diff --git a/services/triggers.py b/services/triggers.py index 043c44bd..cdeb9087 100644 --- a/services/triggers.py +++ b/services/triggers.py @@ -67,7 +67,9 @@ def after_shout_update(_mapper, _connection, shout: Shout): .filter(ShoutAuthor.shout == shout.id) # Filter by shout.id ) - for author_with_stat in get_with_stat(authors_query): + authors_updated = get_with_stat(authors_query) + + for author_with_stat in authors_updated: asyncio.create_task(cache_author(author_with_stat.dict()))