result-fix

This commit is contained in:
Untone 2024-03-04 20:34:11 +03:00
parent e4915dcd7d
commit 2f4747a5de
2 changed files with 14 additions and 9 deletions

View File

@ -43,8 +43,9 @@ async def get_author(_, _info, slug='', author_id=None):
try: try:
if slug: if slug:
q = select(Author).select_from(Author).filter(Author.slug == slug) q = select(Author).select_from(Author).filter(Author.slug == slug)
[author] = get_with_stat(q) result = get_with_stat(q)
if author: if result:
[author] = result
author_id = author.id author_id = author.id
if author_id: if author_id:
@ -55,7 +56,9 @@ async def get_author(_, _info, slug='', author_id=None):
if cache: if cache:
author_dict = json.loads(cache) author_dict = json.loads(cache)
else: else:
[author] = get_with_stat(q) result = get_with_stat(q)
if result:
[author] = result
author_dict = author.dict() 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:
@ -85,9 +88,9 @@ async def get_author_by_user_id(user_id: str):
return author return author
q = select(Author).filter(Author.user == user_id) q = select(Author).filter(Author.user == user_id)
result = get_with_stat(q)
[author] = get_with_stat(q) if result:
if author: [author] = result
await set_author_cache(author.dict()) await set_author_cache(author.dict())
except Exception as exc: except Exception as exc:
import traceback import traceback

View File

@ -133,7 +133,9 @@ def after_reaction_insert(mapper, connection, reaction: Reaction):
@event.listens_for(Author, 'after_update') @event.listens_for(Author, 'after_update')
def after_author_update(mapper, connection, author: Author): def after_author_update(mapper, connection, author: Author):
q = select(Author).where(Author.id == author.id) q = select(Author).where(Author.id == author.id)
[author_with_stat] = get_with_stat(q) result = get_with_stat(q)
if result:
[author_with_stat] = result
asyncio.create_task(set_author_cache(author_with_stat.dict())) asyncio.create_task(set_author_cache(author_with_stat.dict()))