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_query = select(author_alias).filter(author_alias.slug == slug)
result = local_session().execute(author_query).first()
followers = []
if result:
[author] = result
author_id = author.id
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
),
)
results = get_with_stat(q)
if isinstance(results, list):
followers_ids = [r.id for r in results]
for follower in results:
followers = get_with_stat(q)
if isinstance(followers, list):
followers_ids = [r.id for r in followers]
for follower in followers:
if follower.id not in followers_ids:
await cache_follow_author_change(follower.dict(), author.dict())
followers_ids.append(follower.id)
logger.debug(f"@{slug} cache updated with {len(results)} followers")
return results
logger.debug(f"@{slug} cache updated with {len(followers)} followers")
return followers
except Exception as exc:
import traceback

View File

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