From 152730526f6aade6f233efc75471fca3b4fc590a Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 26 Feb 2024 01:06:10 +0300 Subject: [PATCH] get-author-fix --- resolvers/author.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index 7be38735..8cd9ae66 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -38,9 +38,7 @@ def get_authors_all(_, _info): @query.field('get_author') async def get_author(_, _info, slug='', author_id=None): - q = None author = None - cache = None try: if slug: @@ -52,12 +50,11 @@ async def get_author(_, _info, slug='', author_id=None): if author_id: cache = await redis.execute('GET', f'id:{author_id}:author') author = json.loads(cache) - - if not author: - q = select(Author).where(Author.id == author_id) - [author] = get_with_stat(q) - if author: - await update_author_cache(author.dict()) + if not author: + q = select(Author).where(Author.id == author_id) + [author] = get_with_stat(q) + if author: + await update_author_cache(author.dict()) except Exception as exc: logger.error(exc) return author