following-debug
All checks were successful
Deploy on push / deploy (push) Successful in 5m46s

This commit is contained in:
2025-08-30 18:23:15 +03:00
parent f6253f2007
commit f891b73608
4 changed files with 408 additions and 2 deletions

12
cache/cache.py vendored
View File

@@ -308,11 +308,16 @@ async def get_cached_author_followers(author_id: int):
# Get cached follower authors
async def get_cached_follower_authors(author_id: int):
from utils.logger import root_logger as logger
# Attempt to retrieve authors from cache
cached = await redis.execute("GET", f"author:follows-authors:{author_id}")
cache_key = f"author:follows-authors:{author_id}"
cached = await redis.execute("GET", cache_key)
if cached:
authors_ids = orjson.loads(cached)
logger.debug(f"[get_cached_follower_authors] Cache HIT for {cache_key}: {len(authors_ids)} authors")
else:
logger.debug(f"[get_cached_follower_authors] Cache MISS for {cache_key}, querying DB")
# Query authors from database
with local_session() as session:
authors_ids = [
@@ -323,7 +328,10 @@ async def get_cached_follower_authors(author_id: int):
.where(AuthorFollower.follower == author_id)
).all()
]
await redis.execute("SET", f"author:follows-authors:{author_id}", fast_json_dumps(authors_ids))
await redis.execute("SET", cache_key, fast_json_dumps(authors_ids))
logger.debug(
f"[get_cached_follower_authors] DB query result for user {author_id}: {len(authors_ids)} authors, IDs: {authors_ids}"
)
return await get_cached_authors_by_ids(authors_ids)