From 47bc3adb69f3a5e684f46bcfac4da25f99121ec8 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 17 Apr 2024 20:30:05 +0300 Subject: [PATCH] fixes --- resolvers/author.py | 2 ++ services/cache.py | 2 +- services/webhook.py | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index 69b43a9d..018a44c4 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -32,6 +32,8 @@ async def update_author(_, info, profile): Author.update(author, profile) session.add(author) session.commit() + [author] = get_with_stat(select(Author).where(Author.user == user_id)) + await cache_author(author.dict()) return {"error": None, "author": author} except Exception as exc: import traceback diff --git a/services/cache.py b/services/cache.py index 39c38c95..95cf8157 100644 --- a/services/cache.py +++ b/services/cache.py @@ -21,7 +21,7 @@ async def cache_author(author: dict): # update stat all field for followers' caches in list followers_str = await redis.execute("GET", f'author:{author.get("id")}:followers') followers = [] - if followers_str: + if isinstance(followers_str, str): followers = json.loads(followers_str) if isinstance(followers, list): for follower in followers: diff --git a/services/webhook.py b/services/webhook.py index b9e7646c..8f534c39 100644 --- a/services/webhook.py +++ b/services/webhook.py @@ -36,16 +36,19 @@ class WebhookEndpoint(HTTPEndpoint): email: str = user.get("email", "") pic: str = user.get("picture", "") if user_id: - with local_session() as session: - author = session.query(Author).filter(Author.user == user_id).first() + author = ( + session.query(Author).filter(Author.user == user_id).first() + ) if not author: # If the author does not exist, create a new one slug: str = email.split("@")[0].replace(".", "-").lower() slug: str = re.sub("[^0-9a-z]+", "-", slug) while True: author = ( - session.query(Author).filter(Author.slug == slug).first() + session.query(Author) + .filter(Author.slug == slug) + .first() ) if not author: break