diff --git a/resolvers/author.py b/resolvers/author.py index cf037be3..6c6bc0da 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -182,17 +182,17 @@ async def get_author_follows(_, _info, slug='', user=None, author_id=0): rkey = f'author:{author_id}:follows-authors' logger.debug(f'getting {author_id} follows authors') cached = await redis.execute('GET', rkey) + authors = [] if not cached: authors = author_follows_authors(author_id) prepared = [author.dict() for author in authors] - await redis.execute( - 'SET', rkey, json.dumps(prepared, cls=CustomJSONEncoder) - ) + await redis.execute('SET', rkey, json.dumps(prepared, cls=CustomJSONEncoder)) elif isinstance(cached, str): authors = json.loads(cached) rkey = f'author:{author_id}:follows-topics' cached = await redis.execute('GET', rkey) + topics = [] if cached and isinstance(cached, str): topics = json.loads(cached) if not cached: diff --git a/resolvers/stat.py b/resolvers/stat.py index ea17041e..a1fba3cd 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -16,10 +16,17 @@ def add_topic_stat_columns(q): aliased_shout = aliased(Shout) q = ( - q.outerjoin(aliased_shout_topic, and_(aliased_shout_topic.topic == Topic.id, aliased_shout.published_at.is_not(None))) + q.outerjoin(aliased_shout_topic, aliased_shout_topic.topic == Topic.id) .add_columns( func.count(distinct(aliased_shout_topic.shout)).label('shouts_stat') ) + .outerjoin( + aliased_shout_author, + and_( + aliased_shout_topic.shout == aliased_shout_author.shout, + aliased_shout.published_at.is_not(None), + ) + ) .outerjoin( aliased_shout_author, aliased_shout_topic.shout == aliased_shout_author.shout,