From c150d28447f4fd8d07084f83e23cb54d8d471705 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 23 Nov 2023 23:30:00 +0300 Subject: [PATCH] schema-fix --- CHANGELOG.txt | 2 ++ resolvers/reader.py | 39 +++++++++------------------------------ schemas/core.graphql | 14 +++++++------- 3 files changed, 18 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index cd3d93d6..1f9374ca 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,7 @@ [0.2.14] - schema: some fixes from migrator +- schema: .days -> .time_ago +- schema: excludeLayout + layout in filters -> layouts - services: db access simpler, no contextmanager - services: removed Base.create() method - services: rediscache updated diff --git a/resolvers/reader.py b/resolvers/reader.py index f55a7ef6..a5c0ce2a 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -15,9 +15,7 @@ def add_stat_columns(q): aliased_reaction = aliased(Reaction) q = q.outerjoin(aliased_reaction).add_columns( func.sum(aliased_reaction.id).label("reacted_stat"), - func.sum( - case((aliased_reaction.kind == ReactionKind.COMMENT, 1), else_=0) - ).label("commented_stat"), + func.sum(case((aliased_reaction.kind == ReactionKind.COMMENT, 1), else_=0)).label("commented_stat"), func.sum( case( # do not count comments' reactions @@ -54,8 +52,8 @@ def apply_filters(q, filters, author_id=None): if v == "community": q = q.filter(Shout.visibility.in_(["public", "community"])) - if filters.get("layout"): - q = q.filter(Shout.layout == filters.get("layout")) + if filters.get("layouts"): + q = q.filter(Shout.layout.in_(filters.get("layouts"))) if filters.get("author"): q = q.filter(Shout.authors.any(slug=filters.get("author"))) if filters.get("topic"): @@ -104,9 +102,7 @@ async def load_shout(_, _info, slug=None, shout_id=None): "rating": rating_stat, } - for author_caption in ( - session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug) - ): + for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug): for author in shout.authors: if author.id == author_caption.author: author.caption = author_caption.caption @@ -154,18 +150,11 @@ async def load_shouts_by(_, info, options): order_by = options.get("order_by", Shout.published_at) - query_order_by = ( - desc(order_by) if options.get("order_by_desc", True) else asc(order_by) - ) + query_order_by = desc(order_by) if options.get("order_by_desc", True) else asc(order_by) offset = options.get("offset", 0) limit = options.get("limit", 10) - q = ( - q.group_by(Shout.id) - .order_by(nulls_last(query_order_by)) - .limit(limit) - .offset(offset) - ) + q = q.group_by(Shout.id).order_by(nulls_last(query_order_by)).limit(limit).offset(offset) shouts = [] shouts_map = {} @@ -201,10 +190,7 @@ async def get_my_feed(_, info, options): select(Shout.id) .where(Shout.id == ShoutAuthor.shout) .where(Shout.id == ShoutTopic.shout) - .where( - (ShoutAuthor.author.in_(author_followed_authors)) - | (ShoutTopic.topic.in_(author_followed_topics)) - ) + .where((ShoutAuthor.author.in_(author_followed_authors)) | (ShoutTopic.topic.in_(author_followed_topics))) ) q = ( @@ -227,18 +213,11 @@ async def get_my_feed(_, info, options): order_by = options.get("order_by", Shout.published_at) - query_order_by = ( - desc(order_by) if options.get("order_by_desc", True) else asc(order_by) - ) + query_order_by = desc(order_by) if options.get("order_by_desc", True) else asc(order_by) offset = options.get("offset", 0) limit = options.get("limit", 10) - q = ( - q.group_by(Shout.id) - .order_by(nulls_last(query_order_by)) - .limit(limit) - .offset(offset) - ) + q = q.group_by(Shout.id).order_by(nulls_last(query_order_by)).limit(limit).offset(offset) shouts = [] for [ diff --git a/schemas/core.graphql b/schemas/core.graphql index 12df89e9..13910162 100644 --- a/schemas/core.graphql +++ b/schemas/core.graphql @@ -212,7 +212,7 @@ input ReactionInput { shout: Int! range: String body: String - replyTo: Int + reply_to: Int } input AuthorsBy { @@ -222,7 +222,7 @@ input AuthorsBy { name: String topic: String order: String - days: Int + time_ago: Int stat: String } @@ -234,9 +234,9 @@ input ShoutsFilterBy { topics: [String] author: String authors: [String] - layout: String + layouts: [String] visibility: String - days: Int + time_ago: Int stat: String } @@ -245,9 +245,9 @@ input LoadShoutsFilters { body: String topic: String author: String - layout: String + layouts: [String] visibility: String - days: Int + time_ago: Int reacted: Boolean } @@ -267,7 +267,7 @@ input ReactionBy { comment: Boolean topic: String created_by: Int - days: Int + time_ago: Int sort: String }