From 4b111951b7a6ae247c845fbc72f1802358583662 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 14 Nov 2024 00:55:25 +0300 Subject: [PATCH] unrated-fix --- resolvers/reader.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index 8447e660..93b7ce91 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -439,8 +439,19 @@ async def load_shouts_unrated(_, info, options): .scalar_subquery() ) - q = query_with_stat(info) - q = q.where(~Shout.id.in_(rated_shouts)) + q = ( + select(Shout) + .where(and_(Shout.published_at.is_not(None), Shout.deleted_at.is_(None))) + .join(Author, Author.id == Shout.created_by) + ) + q = q.join(ShoutTopic, and_(ShoutTopic.shout == Shout.id, ShoutTopic.main.is_(True))) + q = q.join(Topic, Topic.id == ShoutTopic.topic) + q = q.add_columns( + json_builder( + "id", Topic.id, "title", Topic.title, "slug", Topic.slug + ).label("main_topic") + ) + q = q.where(Shout.id.not_in(rated_shouts)) q = q.order_by(func.random()) limit = options.get("limit", 5)