This commit is contained in:
parent
e103b283cb
commit
8826af02b5
|
@ -60,28 +60,27 @@ async def get_author(_, _info, slug='', author_id=None):
|
||||||
if slug:
|
if slug:
|
||||||
author_id = local_session().query(Author.id).filter(Author.slug == slug)
|
author_id = local_session().query(Author.id).filter(Author.slug == slug)
|
||||||
logger.debug(f'found @{slug} with id {author_id}')
|
logger.debug(f'found @{slug} with id {author_id}')
|
||||||
if author_id:
|
if author_id:
|
||||||
cache_key = f'author:{author_id}'
|
cache_key = f'author:{author_id}'
|
||||||
cache = await redis.execute('GET', cache_key)
|
cache = await redis.execute('GET', cache_key)
|
||||||
logger.debug(f'GET {cache_key} -> {cache}')
|
author_dict = None
|
||||||
|
if cache and isinstance(cache, str):
|
||||||
|
logger.debug(f'got cached author {cache_key} -> {cache}')
|
||||||
|
author_dict = json.loads(cache)
|
||||||
|
else:
|
||||||
q = select(Author).where(Author.id == author_id)
|
q = select(Author).where(Author.id == author_id)
|
||||||
author_dict = None
|
[author] = await get_authors_with_stat_cached(q)
|
||||||
if cache and isinstance(cache, str):
|
if author:
|
||||||
author_dict = json.loads(cache)
|
author_dict = author.dict()
|
||||||
else:
|
else:
|
||||||
result = await get_authors_with_stat_cached(q)
|
logger.warn('author was not cached!')
|
||||||
if result:
|
author_query = select(Author).filter(Author.id == author_id)
|
||||||
[author] = result
|
[author] = get_with_stat(author_query)
|
||||||
author_dict = author.dict()
|
author_dict = author.dict()
|
||||||
else:
|
if author_dict:
|
||||||
logger.warn('author was not cached!')
|
await set_author_cache(author_dict)
|
||||||
author_query = select(Author).filter(Author.id == author_id)
|
logger.debug('author stored in cache')
|
||||||
[author] = get_with_stat(author_query)
|
return author_dict
|
||||||
author_dict = author.dict()
|
|
||||||
if author_dict:
|
|
||||||
await set_author_cache(author_dict)
|
|
||||||
logger.debug('author stored in cache')
|
|
||||||
return author_dict
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user