From b02b8276a6c5c39299df4d0cf799a2fb58f79595 Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 25 Feb 2024 22:45:36 +0300 Subject: [PATCH] get-author-fix --- resolvers/author.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index dda78c12..69898a1b 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -42,22 +42,24 @@ async def get_author(_, _info, slug='', author_id=None): author = None cache = None try: + if slug: with local_session() as session: aliased_author = aliased(Author) q = select(aliased_author).filter(aliased_author.slug == slug) [author] = session.execute(q) author_id = aliased_author.id + if author_id: cache = await redis.execute('GET', f'id:{author_id}:author') - if not cache: + author = json.loads(cache) + + if not author: aliased_author = aliased(Author) q = select(aliased_author).where(aliased_author.id == author_id) [author] = get_with_stat(q) if author: await update_author_cache(author.dict()) - else: - author = json.loads(cache) except Exception as exc: logger.error(exc) return author