This commit is contained in:
parent
ad5b4a81c3
commit
caf45f3d42
|
@ -50,7 +50,12 @@ async def get_author(_, _info, slug='', author_id=None):
|
||||||
cache = await redis.execute('GET', f'id:{author_id}:author')
|
cache = await redis.execute('GET', f'id:{author_id}:author')
|
||||||
logger.debug(f'result from cache: {cache}')
|
logger.debug(f'result from cache: {cache}')
|
||||||
q = select(Author).where(Author.id == author_id)
|
q = select(Author).where(Author.id == author_id)
|
||||||
author_dict = json.loads(cache) if cache else get_with_stat(q)[0].dict()
|
author_dict = None
|
||||||
|
if cache:
|
||||||
|
author_dict = json.loads(cache)
|
||||||
|
else:
|
||||||
|
[author] = get_with_stat(q)
|
||||||
|
author_dict = author.dict()
|
||||||
logger.debug(f'author to be stored: {author_dict}')
|
logger.debug(f'author to be stored: {author_dict}')
|
||||||
if author:
|
if author:
|
||||||
await update_author_cache(author_dict)
|
await update_author_cache(author_dict)
|
||||||
|
|
|
@ -57,6 +57,9 @@ class Base(declarative_base()):
|
||||||
data[c] = json.loads(str(value))
|
data[c] = json.loads(str(value))
|
||||||
else:
|
else:
|
||||||
data[c] = value
|
data[c] = value
|
||||||
|
# Add synthetic field .stat
|
||||||
|
if hasattr(self, 'stat'):
|
||||||
|
data['stat'] = self.stat
|
||||||
return data
|
return data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Error occurred while converting object to dictionary: {e}')
|
logger.error(f'Error occurred while converting object to dictionary: {e}')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user