From 499ecb501d98970871724bc71c1d3acc357b6515 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 6 May 2024 19:40:51 +0300 Subject: [PATCH] load-authors-fix --- resolvers/author.py | 11 +++++++++-- resolvers/stat.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index d2c87b3d..de92aede 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -154,13 +154,20 @@ async def load_authors_by(_, _info, by, limit, offset): authors = [] if authors_nostat: for [a] in authors_nostat: + author_dict = None if isinstance(a, Author): author_id = a.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) - authors.append(author_dict) + if not author_dict or not isinstance(author_dict.get("shouts"), int): + author_query = q.filter(Author.id == author_id) + [author] = get_with_stat(author_query) + if author: + author_dict = author.dict() + if author_dict: + authors.append(author_dict) return authors @@ -315,7 +322,7 @@ async def get_author_followers(_, _info, slug: str): if isinstance(followers_cached, list): logger.debug(f"@{slug} got {followers_cached} followers cached") for fc in followers_cached: - if fc['id'] not in followers_ids: + if fc["id"] not in followers_ids: followers.append(fc) return followers diff --git a/resolvers/stat.py b/resolvers/stat.py index eeaea1bb..1aa9580f 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -124,7 +124,7 @@ def get_author_shouts_stat(author_id: int): .filter( and_( aliased_shout_author.author == author_id, - aliased_shout.published_at.is_not(None) + aliased_shout.published_at.is_not(None), ) ) )