From a9ab2e8bb29f6e00d1180ad993139788d23c8eea Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 27 May 2024 20:03:07 +0300 Subject: [PATCH] cached-empty-fix-4 --- resolvers/author.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index f453a39e..abaa29f8 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -328,13 +328,15 @@ async def get_author_followers(_, _info, slug: str): author_id = author.id cached = await redis.execute("GET", f"author:{author_id}:followers") - if cached: - followers_cached = json.loads(cached) - if isinstance(followers_cached, list) and len(followers_cached) > 0: - logger.debug( - f"@{slug} got {len(followers_cached)} followers cached" - ) - return followers_cached + cached_author = await redis.execute("GET", f"author:{author_id}") + if cached and cached_author: + followers = json.loads(cached) + author_dict = json.loads(cached_author) + if isinstance(followers, list) and str(len(followers)) == str( + author_dict["stat"]["followers"] + ): + logger.debug(f"@{slug} got {len(followers)} followers cached") + return followers author_follower_alias = aliased(AuthorFollower, name="af") followers_query = select(Author).join(