From d4c16658bd4eb50a0e4807f5ad70949e1a2f7cbf Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 29 May 2025 12:15:06 +0300 Subject: [PATCH] author-user-fix --- cache/cache.py | 15 +++++++-------- resolvers/author.py | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cache/cache.py b/cache/cache.py index 1bb4564c..ef535d5c 100644 --- a/cache/cache.py +++ b/cache/cache.py @@ -60,7 +60,6 @@ CACHE_KEYS = { "TOPIC_FOLLOWERS": "topic:followers:{}", "TOPIC_SHOUTS": "topic_shouts_{}", "AUTHOR_ID": "author:id:{}", - "AUTHOR_USER": "author:user:{}", "SHOUTS": "shouts:{}", } @@ -300,19 +299,19 @@ async def get_cached_follower_topics(author_id: int): return topics -# Get author by user ID from cache -async def get_cached_author_by_id(user_id: str, get_with_stat): +# Get author by author_id from cache +async def get_cached_author_by_id(author_id: int, get_with_stat): """ - Retrieve author information by user_id, checking the cache first, then the database. + Retrieve author information by author_id, checking the cache first, then the database. Args: - user_id (str): The user identifier for which to retrieve the author. + author_id (int): The author identifier for which to retrieve the author. Returns: dict: Dictionary with author data or None if not found. """ - # Attempt to find author ID by user_id in Redis cache - author_id = await redis.execute("GET", f"author:user:{author_id}") + # Attempt to find author ID by author_id in Redis cache + author_id = await redis.execute("GET", f"author:id:{author_id}") if author_id: # If ID is found, get full author data by ID author_data = await redis.execute("GET", f"author:id:{author_id}") @@ -406,7 +405,7 @@ async def invalidate_shouts_cache(cache_keys: List[str]): logger.debug(f"Invalidated related key: {related_key}") except Exception as e: - logger.error(f"Error invalidating cache key {key}: {e}") + logger.error(f"Error invalidating cache key {cache_key}: {e}") async def cache_topic_shouts(topic_id: int, shouts: List[dict]): diff --git a/resolvers/author.py b/resolvers/author.py index 774af1ce..3adea6d8 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -252,11 +252,11 @@ async def invalidate_authors_cache(author_id=None): f"author:follows-shouts:{author_id}", ] - # Получаем user_id автора, если есть + # Получаем author_id автора, если есть with local_session() as session: author = session.query(Author).filter(Author.id == author_id).first() if author and Author.id: - specific_keys.append(f"author:user:{Author.id.strip()}") + specific_keys.append(f"author:id:{Author.id}") # Удаляем конкретные ключи for key in specific_keys: