This commit is contained in:
@@ -40,9 +40,20 @@ async def follow(
|
||||
) -> dict[str, Any]:
|
||||
logger.debug("Начало выполнения функции 'follow'")
|
||||
viewer_id = info.context.get("author", {}).get("id")
|
||||
follower_dict = info.context.get("author") or {}
|
||||
|
||||
# ✅ КРИТИЧНО: Инвалидируем кеш В САМОМ НАЧАЛЕ, если пользователь авторизован
|
||||
# чтобы предотвратить чтение старых данных при последующей перезагрузке
|
||||
if viewer_id:
|
||||
entity_type = what.lower()
|
||||
cache_key_pattern = f"author:follows-{entity_type}s:{viewer_id}"
|
||||
await redis.execute("DEL", cache_key_pattern)
|
||||
await redis.execute("DEL", f"author:id:{viewer_id}")
|
||||
logger.debug(f"Инвалидирован кеш подписок follower'а: {cache_key_pattern}")
|
||||
|
||||
if not viewer_id:
|
||||
return {"error": "Access denied"}
|
||||
follower_dict = info.context.get("author") or {}
|
||||
|
||||
logger.debug(f"follower: {follower_dict}")
|
||||
|
||||
if not viewer_id or not follower_dict:
|
||||
@@ -52,14 +63,6 @@ async def follow(
|
||||
follower_id = follower_dict.get("id")
|
||||
logger.debug(f"follower_id: {follower_id}")
|
||||
|
||||
# ✅ КРИТИЧНО: Инвалидируем кеш В САМОМ НАЧАЛЕ, ДО любых операций
|
||||
# чтобы предотвратить чтение старых данных при последующей перезагрузке
|
||||
entity_type = what.lower()
|
||||
cache_key_pattern = f"author:follows-{entity_type}s:{follower_id}"
|
||||
await redis.execute("DEL", cache_key_pattern)
|
||||
await redis.execute("DEL", f"author:id:{follower_id}")
|
||||
logger.debug(f"Инвалидирован кеш подписок follower'а: {cache_key_pattern}")
|
||||
|
||||
entity_classes = {
|
||||
"AUTHOR": (Author, AuthorFollower, get_cached_follower_authors, cache_author),
|
||||
"TOPIC": (Topic, TopicFollower, get_cached_follower_topics, cache_topic),
|
||||
@@ -206,9 +209,19 @@ async def unfollow(
|
||||
) -> dict[str, Any]:
|
||||
logger.debug("Начало выполнения функции 'unfollow'")
|
||||
viewer_id = info.context.get("author", {}).get("id")
|
||||
follower_dict = info.context.get("author") or {}
|
||||
|
||||
# ✅ КРИТИЧНО: Инвалидируем кеш В САМОМ НАЧАЛЕ, если пользователь авторизован
|
||||
if viewer_id:
|
||||
entity_type = what.lower()
|
||||
cache_key_pattern = f"author:follows-{entity_type}s:{viewer_id}"
|
||||
await redis.execute("DEL", cache_key_pattern)
|
||||
await redis.execute("DEL", f"author:id:{viewer_id}")
|
||||
logger.debug(f"Инвалидирован кеш подписок В НАЧАЛЕ операции unfollow: {cache_key_pattern}")
|
||||
|
||||
if not viewer_id:
|
||||
return {"error": "Access denied"}
|
||||
follower_dict = info.context.get("author") or {}
|
||||
|
||||
logger.debug(f"follower: {follower_dict}")
|
||||
|
||||
if not viewer_id or not follower_dict:
|
||||
@@ -218,13 +231,6 @@ async def unfollow(
|
||||
follower_id = follower_dict.get("id")
|
||||
logger.debug(f"follower_id: {follower_id}")
|
||||
|
||||
# ✅ КРИТИЧНО: Инвалидируем кеш В САМОМ НАЧАЛЕ, ДО любых операций
|
||||
entity_type = what.lower()
|
||||
cache_key_pattern = f"author:follows-{entity_type}s:{follower_id}"
|
||||
await redis.execute("DEL", cache_key_pattern)
|
||||
await redis.execute("DEL", f"author:id:{follower_id}")
|
||||
logger.debug(f"Инвалидирован кеш подписок В НАЧАЛЕ операции unfollow: {cache_key_pattern}")
|
||||
|
||||
entity_classes = {
|
||||
"AUTHOR": (Author, AuthorFollower, get_cached_follower_authors, cache_author),
|
||||
"TOPIC": (Topic, TopicFollower, get_cached_follower_topics, cache_topic),
|
||||
|
||||
Reference in New Issue
Block a user