cached-empty-fix-4

This commit is contained in:
Untone 2024-05-27 20:03:07 +03:00
parent 9a94e5ac56
commit a9ab2e8bb2

View File

@ -328,13 +328,15 @@ async def get_author_followers(_, _info, slug: str):
author_id = author.id author_id = author.id
cached = await redis.execute("GET", f"author:{author_id}:followers") cached = await redis.execute("GET", f"author:{author_id}:followers")
if cached: cached_author = await redis.execute("GET", f"author:{author_id}")
followers_cached = json.loads(cached) if cached and cached_author:
if isinstance(followers_cached, list) and len(followers_cached) > 0: followers = json.loads(cached)
logger.debug( author_dict = json.loads(cached_author)
f"@{slug} got {len(followers_cached)} followers cached" if isinstance(followers, list) and str(len(followers)) == str(
) author_dict["stat"]["followers"]
return followers_cached ):
logger.debug(f"@{slug} got {len(followers)} followers cached")
return followers
author_follower_alias = aliased(AuthorFollower, name="af") author_follower_alias = aliased(AuthorFollower, name="af")
followers_query = select(Author).join( followers_query = select(Author).join(