This commit is contained in:
12
cache/cache.py
vendored
12
cache/cache.py
vendored
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user