diff --git a/resolvers/reader.py b/resolvers/reader.py index df51aa07..4d22ba4f 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -49,34 +49,34 @@ def query_shouts(): ) ).label("rating_stat"), func.max(aliased_reaction.created_at).label("last_reacted_at"), - func.json_agg( - func.json_build_object( - "id", - Author.id, - "name", - Author.name, - "slug", - Author.slug, - "pic", - Author.pic, + func.array_agg( + func.distinct( + func.json_build_object( + "id", + Author.id, + "name", + Author.name, + "slug", + Author.slug, + "pic", + Author.pic, + ) ) - ) - .filter(Author.id.is_not(None)) - .label("authors"), - func.json_agg( - func.json_build_object( - "id", - Topic.id, - "title", - Topic.title, - "body", - Topic.body, - "slug", - Topic.slug, + ).label("authors"), + func.array_agg( + func.distinct( + func.json_build_object( + "id", + Topic.id, + "title", + Topic.title, + "body", + Topic.body, + "slug", + Topic.slug, + ) ) - ) - .filter(Topic.id.is_not(None)) - .label("topics"), + ).label("topics"), ) .outerjoin(aliased_reaction, aliased_reaction.shout == Shout.id) .outerjoin(shout_author, shout_author.shout == Shout.id) @@ -84,7 +84,7 @@ def query_shouts(): .outerjoin(shout_topic, shout_topic.shout == Shout.id) .outerjoin(Topic, Topic.id == shout_topic.topic) .where(and_(Shout.published_at.is_not(None), Shout.deleted_at.is_(None))) - .group_by(Shout.id, Author.id, Topic.id) + .group_by(Shout.id) ) return q, aliased_reaction