From f0fc09b1a1c2009c2c348b17e269525023cbe096 Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Fri, 18 Nov 2022 03:19:10 +0100 Subject: [PATCH] fixes --- resolvers/profile.py | 2 +- resolvers/reactions.py | 12 +++++------- resolvers/zine.py | 19 +++++++++++-------- schema.graphql | 4 ++-- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/resolvers/profile.py b/resolvers/profile.py index 6e051950..cacf64a5 100644 --- a/resolvers/profile.py +++ b/resolvers/profile.py @@ -210,5 +210,5 @@ async def load_authors_by(_, info, by, limit, offset): for a in authors: a.stat = await get_author_stat(a.slug) authors = list(set(authors)) - authors = sorted(authors, key=lambda a: a["stat"].get(by.get("stat"))) + # authors = sorted(authors, key=lambda a: a["stat"].get(by.get("stat"))) return authors diff --git a/resolvers/reactions.py b/resolvers/reactions.py index 2ca7ebd2..e410b2f1 100644 --- a/resolvers/reactions.py +++ b/resolvers/reactions.py @@ -217,13 +217,10 @@ async def load_reactions_by(_, info, by, limit=50, offset=0): :return: Reaction[] """ - q = select(Reaction).options( - selectinload(Reaction.shout), + q = select(Reaction).join( + Shout ).where( Reaction.deletedAt.is_(None) - ).join( - Shout, - Shout.slug == Reaction.shout ) if by.get("slug"): q = q.filter(Shout.slug == by["slug"]) @@ -243,8 +240,9 @@ async def load_reactions_by(_, info, by, limit=50, offset=0): if by.get("days"): before = datetime.now() - timedelta(days=int(by["days"]) or 30) q = q.filter(Reaction.createdAt > before) - q = q.group_by(Shout.id).order_by( - desc(by.get("order") or "createdAt") + + q = q.group_by(Reaction.id).order_by( + desc(by.get("order") or Reaction.createdAt) ).limit(limit).offset(offset) rrr = [] diff --git a/resolvers/zine.py b/resolvers/zine.py index f64205c7..9c7efab8 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -18,15 +18,18 @@ from services.stat.reacted import ReactedStorage @query.field("loadShout") async def load_shout(_, info, slug): - shout = select(Shout).options( - # TODO add cation - selectinload(Shout.authors), - selectinload(Shout.topics), - ).where( - Shout.deletedAt.is_(None) - ).one() + with local_session() as session: + shout = session.query(Shout).options( + # TODO add cation + selectinload(Shout.authors), + selectinload(Shout.topics), + ).filter( + Shout.slug == slug + ).filter( + Shout.deletedAt.is_(None) + ).one() - return shout + return shout @query.field("loadShouts") diff --git a/schema.graphql b/schema.graphql index 68db86f1..214547bf 100644 --- a/schema.graphql +++ b/schema.graphql @@ -277,7 +277,7 @@ type Query { userFollowedAuthors(slug: String!): [Author]! userFollowedTopics(slug: String!): [Topic]! authorsAll: [Author]! - getAuthor(slug: String!): User! + getAuthor(slug: String!): User # collab getCollabs: [Collab]! @@ -286,7 +286,7 @@ type Query { markdownBody(body: String!): String! # topics - getTopic(slug: String!): Topic! + getTopic(slug: String!): Topic topicsAll: [Topic]! topicsRandom(amount: Int): [Topic]! topicsByCommunity(community: String!): [Topic]!