From 1e0d0f465a3a8bbd79569020669c665581e90e6d Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 5 Jun 2024 18:46:01 +0300 Subject: [PATCH] get_cached_author-fix --- services/cache.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/cache.py b/services/cache.py index 44bc1ff9..d68f36b7 100644 --- a/services/cache.py +++ b/services/cache.py @@ -77,9 +77,15 @@ 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): author_dict = await redis.execute("GET", f"author:user:{user_id}") - author_id = author_dict.get("id") + author_id = None + if not author_dict: + with local_session() as session: + author_id = session.query(Author.id).filter(Author.user == user_id).first() + else: + author_id = author_dict.get("id") if author_id: - return await get_cached_author(int(author_id), get_with_stat) + cached_author = await get_cached_author(int(author_id), get_with_stat) + return cached_author async def get_cached_topic_by_slug(slug: str, get_with_stat):