From 0e1df1e7cab6b279511a845dcc99222e30dcd0f4 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 12 Mar 2024 08:00:42 +0300 Subject: [PATCH] followers-update-fix --- services/cache.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/cache.py b/services/cache.py index 98bf3ad7..9ae1434e 100644 --- a/services/cache.py +++ b/services/cache.py @@ -27,7 +27,7 @@ async def set_author_cache(author: dict): async def update_author_followers_cache(author_id: int, followers): - payload = json.dumps(followers, cls=CustomJSONEncoder) + payload = json.dumps([f.dict() if isinstance(f, Author) else f for f in followers], cls=CustomJSONEncoder) await redis.execute('SET', f'author:{author_id}:followers', payload) @@ -84,7 +84,9 @@ async def update_followers_for_author( ): redis_key = f'author:{author.id}:followers' followers_str = await redis.execute('GET', redis_key) - followers = json.loads(followers_str) if followers_str else [] + followers = [] + if isinstance(followers_str, str): + followers = json.loads(followers_str) if is_insert: followers.append(follower) else: