author-id-faster
Some checks failed
Deploy on push / deploy (push) Failing after 20s

This commit is contained in:
Untone 2024-03-13 12:44:08 +03:00
parent 13e2a4b7ba
commit 13bff800f0

View File

@ -44,29 +44,24 @@ async def get_author(_, _info, slug='', author_id=None):
author = None author = None
try: try:
if slug: if slug:
q = select(Author).select_from(Author).filter(Author.slug == slug) [author_id] = local_session().execute(Author.id).filter(Author.slug == slug).scalar()
result = await get_authors_with_stat_cached(q) if author_id:
if result: cache_key = f'author:{author_id}'
[author] = result cache = await redis.execute('GET', cache_key)
author_id = author.id logger.debug(f'result from {cache_key}: {cache}')
q = select(Author).where(Author.id == author_id)
if author_id: author_dict = None
cache_key = f'author:{author_id}' if cache:
cache = await redis.execute('GET', cache_key) author_dict = json.loads(cache)
logger.debug(f'result from {cache_key}: {cache}') else:
q = select(Author).where(Author.id == author_id) result = await get_authors_with_stat_cached(q)
author_dict = None if result:
if cache: [author] = result
author_dict = json.loads(cache) author_dict = author.dict()
else: logger.debug(f'author to be stored: {author_dict}')
result = await get_authors_with_stat_cached(q) if author:
if result: await set_author_cache(author_dict)
[author] = result return author_dict
author_dict = author.dict()
logger.debug(f'author to be stored: {author_dict}')
if author:
await set_author_cache(author_dict)
return author_dict
except Exception as exc: except Exception as exc:
import traceback import traceback