refactored-get-author
All checks were successful
Deploy on push / deploy (push) Successful in 24s

This commit is contained in:
Untone 2024-03-28 19:05:27 +03:00
parent e103b283cb
commit 8826af02b5

View File

@ -63,15 +63,14 @@ async def get_author(_, _info, slug='', author_id=None):
if author_id:
cache_key = f'author:{author_id}'
cache = await redis.execute('GET', cache_key)
logger.debug(f'GET {cache_key} -> {cache}')
q = select(Author).where(Author.id == author_id)
author_dict = None
if cache and isinstance(cache, str):
logger.debug(f'got cached author {cache_key} -> {cache}')
author_dict = json.loads(cache)
else:
result = await get_authors_with_stat_cached(q)
if result:
[author] = result
q = select(Author).where(Author.id == author_id)
[author] = await get_authors_with_stat_cached(q)
if author:
author_dict = author.dict()
else:
logger.warn('author was not cached!')