redis-set-set-fix
All checks were successful
Deploy on push / deploy (push) Successful in 27s

This commit is contained in:
Untone 2024-05-07 21:56:07 +03:00
parent cfcb858bba
commit 69409f92e1
2 changed files with 37 additions and 37 deletions

View File

@ -305,7 +305,8 @@ async def get_author_followers(_, _info, slug: str):
author_alias = aliased(Author) author_alias = aliased(Author)
author_query = select(author_alias).filter(author_alias.slug == slug) author_query = select(author_alias).filter(author_alias.slug == slug)
result = local_session().execute(author_query).first() result = local_session().execute(author_query).first()
followers = []
if result:
[author] = result [author] = result
author_id = author.id author_id = author.id
cached = await redis.execute("GET", f"author:{author_id}:followers") cached = await redis.execute("GET", f"author:{author_id}:followers")
@ -333,15 +334,15 @@ async def get_author_followers(_, _info, slug: str):
Author.id != author_id, # exclude the author from the followers Author.id != author_id, # exclude the author from the followers
), ),
) )
results = get_with_stat(q) followers = get_with_stat(q)
if isinstance(results, list): if isinstance(followers, list):
followers_ids = [r.id for r in results] followers_ids = [r.id for r in followers]
for follower in results: for follower in followers:
if follower.id not in followers_ids: if follower.id not in followers_ids:
await cache_follow_author_change(follower.dict(), author.dict()) await cache_follow_author_change(follower.dict(), author.dict())
followers_ids.append(follower.id) followers_ids.append(follower.id)
logger.debug(f"@{slug} cache updated with {len(results)} followers") logger.debug(f"@{slug} cache updated with {len(followers)} followers")
return results return followers
except Exception as exc: except Exception as exc:
import traceback import traceback

View File

@ -164,7 +164,6 @@ async def cache_topic(topic_dict: dict):
follower_follows_topics.append(topic_dict) follower_follows_topics.append(topic_dict)
await redis.execute( await redis.execute(
"SET",
"SET", "SET",
f"author:{follower_id}:follows-topics", f"author:{follower_id}:follows-topics",
json.dumps(follower_follows_topics, cls=CustomJSONEncoder), json.dumps(follower_follows_topics, cls=CustomJSONEncoder),