get-author-followers-fix
All checks were successful
Deploy on push / deploy (push) Successful in 24s

This commit is contained in:
Untone 2024-02-27 16:42:26 +03:00
parent eadae7f639
commit fa7b05a86e

View File

@ -225,6 +225,7 @@ async def get_author_followers(_, _info, slug: str):
author = author_id_result[0] if author_id_result else None author = author_id_result[0] if author_id_result else None
author_id = cast(author.id, Integer) author_id = cast(author.id, Integer)
cached = await redis.execute('GET', f'id:{author_id}:followers') cached = await redis.execute('GET', f'id:{author_id}:followers')
results = []
if not cached: if not cached:
author_follower_alias = aliased(AuthorFollower, name='af') author_follower_alias = aliased(AuthorFollower, name='af')
q = select(Author).join( q = select(Author).join(
@ -234,7 +235,8 @@ async def get_author_followers(_, _info, slug: str):
author_follower_alias.follower == Author.id, author_follower_alias.follower == Author.id,
), ),
) )
return json.loads(cached) if cached else get_with_stat(q) results = get_with_stat(q)
return json.loads(cached) if cached else results
except Exception as exc: except Exception as exc:
import traceback import traceback
logger.error(exc) logger.error(exc)