following-cache-anyway-found

This commit is contained in:
2024-05-05 20:16:45 +03:00
parent cfe9ac1005
commit 3ab42ecb72
4 changed files with 14 additions and 16 deletions

View File

@@ -156,7 +156,7 @@ async def load_authors_by(_, _info, by, limit, offset):
for [a] in authors_nostat:
if isinstance(a, Author):
author_id = a.id
if author_id:
if bool(author_id):
cached_result = await redis.execute("GET", f"author:{author_id}")
if isinstance(cached_result, str):
author_dict = json.loads(cached_result)
@@ -187,12 +187,12 @@ async def get_author_follows(_, _info, slug="", user=None, author_id=0):
author_id = author.id if not author_id else author_id
topics = []
authors = []
if author_id:
if bool(author_id):
rkey = f"author:{author_id}:follows-authors"
logger.debug(f"getting {author_id} follows authors")
cached = await redis.execute("GET", rkey)
if not cached:
authors = author_follows_authors(author_id)
authors = author_follows_authors(author_id) # type: ignore
prepared = [author.dict() for author in authors]
await redis.execute(
"SET", rkey, json.dumps(prepared, cls=CustomJSONEncoder)
@@ -205,7 +205,7 @@ async def get_author_follows(_, _info, slug="", user=None, author_id=0):
if cached and isinstance(cached, str):
topics = json.loads(cached)
if not cached:
topics = author_follows_topics(author_id)
topics = author_follows_topics(author_id) # type: ignore
prepared = [topic.dict() for topic in topics]
await redis.execute(
"SET", rkey, json.dumps(prepared, cls=CustomJSONEncoder)

View File

@@ -51,10 +51,7 @@ async def follow(_, info, what, slug):
follows = []
follows_str = await redis.execute("GET", f"author:{follower_id}:follows-{entity}s")
if isinstance(follows_str, str):
follows = json.loads(follows_str)
if not follows:
return {"error": "cant find following cache"}
follows = json.loads(follows_str) or []
if what == "AUTHOR":
follower_id = int(follower_id)
@@ -105,7 +102,7 @@ async def unfollow(_, info, what, slug):
follows = []
follows_str = await redis.execute("GET", f"author:{follower_id}:follows-{entity}s")
if isinstance(follows_str, str):
follows = json.loads(follows_str)
follows = json.loads(follows_str) or []
if what == "AUTHOR":
error = author_unfollow(follower_id, slug)