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

This commit is contained in:
Untone 2024-02-26 01:06:10 +03:00
parent f12d2fc560
commit 152730526f

View File

@ -38,9 +38,7 @@ def get_authors_all(_, _info):
@query.field('get_author') @query.field('get_author')
async def get_author(_, _info, slug='', author_id=None): async def get_author(_, _info, slug='', author_id=None):
q = None
author = None author = None
cache = None
try: try:
if slug: if slug:
@ -52,12 +50,11 @@ async def get_author(_, _info, slug='', author_id=None):
if author_id: if author_id:
cache = await redis.execute('GET', f'id:{author_id}:author') cache = await redis.execute('GET', f'id:{author_id}:author')
author = json.loads(cache) author = json.loads(cache)
if not author:
if not author: q = select(Author).where(Author.id == author_id)
q = select(Author).where(Author.id == author_id) [author] = get_with_stat(q)
[author] = get_with_stat(q) if author:
if author: await update_author_cache(author.dict())
await update_author_cache(author.dict())
except Exception as exc: except Exception as exc:
logger.error(exc) logger.error(exc)
return author return author