This commit is contained in:
parent
1eeff25b4d
commit
495b296508
|
@ -58,12 +58,14 @@ async def get_author(_, _info, slug='', author_id=None):
|
|||
author_dict = None
|
||||
try:
|
||||
author_query = ''
|
||||
author = None
|
||||
author_dict = None
|
||||
if slug:
|
||||
author_query = select(Author.id).filter(Author.slug == slug)
|
||||
author_id = local_session().execute(author_query).scalar()
|
||||
author_query = select(Author).filter(Author.slug == slug)
|
||||
[author] = await get_authors_with_stat_cached(author_query)
|
||||
logger.debug(f'found @{slug} with id {author_id}')
|
||||
if author_id:
|
||||
if isinstance(author, Author):
|
||||
author_id = author.id
|
||||
author_query = select(Author.id).filter(Author.id == author_id)
|
||||
cache_key = f'author:{author_id}'
|
||||
cache = await redis.execute('GET', cache_key)
|
||||
|
|
|
@ -202,7 +202,7 @@ async def get_authors_with_stat_cached(q):
|
|||
records = []
|
||||
with local_session() as session:
|
||||
for [x] in session.execute(q):
|
||||
stat_str = await redis.execute('GET', f'author:{x.id if isinstance(x, Author) else x}')
|
||||
stat_str = await redis.execute('GET', f'author:{x.id}')
|
||||
x.stat = json.loads(stat_str).get('stat') if isinstance(stat_str, str) else {}
|
||||
records.append(x)
|
||||
except Exception as exc:
|
||||
|
|
Loading…
Reference in New Issue
Block a user