diff --git a/services/cache.py b/services/cache.py index 624703e6..98e4198d 100644 --- a/services/cache.py +++ b/services/cache.py @@ -28,7 +28,7 @@ async def cache_topic(topic: dict): async def cache_author(author: dict): author_id = author.get("id") - user_id = author.get("user") + user_id = author.get("user", "").strip() payload = json.dumps(author, cls=CustomJSONEncoder) await redis.execute("SET", f"author:user:{user_id}", payload) await redis.execute("SET", f"author:id:{author_id}", payload) @@ -76,7 +76,7 @@ async def get_cached_author(author_id: int, get_with_stat): async def get_cached_author_by_user_id(user_id: str, get_with_stat) -> dict: - author_str = await redis.execute("GET", f"author:user:{user_id}") + author_str = await redis.execute("GET", f"author:user:{user_id.strip()}") author_dict = None if not author_str: author_query = select(Author).filter(Author.user == user_id) diff --git a/services/precache.py b/services/precache.py index eef916a7..3e09c3ec 100644 --- a/services/precache.py +++ b/services/precache.py @@ -111,7 +111,7 @@ async def precache_data(): for author in authors: profile = author.dict() if not isinstance(author, dict) else author author_id = profile.get("id") - user_id = profile.get("user") + user_id = profile.get("user","").strip() if author_id and user_id: authors_by_id[author_id] = profile author_payload = json.dumps(profile, cls=CustomJSONEncoder)