From 2e705fa2c9e9f7a498e25106276e9ed9e664dfd6 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sun, 13 Nov 2022 12:25:02 +0300 Subject: [PATCH] refactoring-wip --- resolvers/zine.py | 16 +++++++++++++--- schema.graphql | 5 +++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/resolvers/zine.py b/resolvers/zine.py index 7fa3be87..271740b5 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -125,8 +125,12 @@ async def shouts_by_authors(_, _info, slugs, offset=0, limit=100): return shouts_prepared[offset : offset + limit] -@query.field("shoutsByLayout") -async def shouts_by_layout(_, _info, layout, amount=100, offset=0): +@query.field("recentLayoutShouts") +@query.field("topLayoutShouts") +@query.field("topMonthLayoutShouts") +async def shouts_by_layout(param, info, layout, amount=100, offset=0): + print(param) + print(info) async with ShoutsCache.lock: shouts = {} # for layout in ['image', 'audio', 'video', 'literature']: @@ -137,7 +141,13 @@ async def shouts_by_layout(_, _info, layout, amount=100, offset=0): # if bool(s.publishedAt): shouts[s.slug] = s shouts_prepared = list(shouts.values()) - shouts_prepared.sort(key=lambda s: s.createdAt, reverse=True) + + # TODO: pick keyfunc according to kind of query + + def keyfunc(s): + return s.createdAt + + shouts_prepared.sort(key=keyfunc, reverse=True) return shouts_prepared[offset : offset + amount] diff --git a/schema.graphql b/schema.graphql index bc0c9202..47cf74f3 100644 --- a/schema.graphql +++ b/schema.graphql @@ -261,6 +261,11 @@ type Query { recentAll(offset: Int!, limit: Int!): [Shout]! recentCandidates(offset: Int!, limit: Int!): [Shout]! + # expo + topMonthLayoutShouts(layout: String!, amount: Int, offset: Int): [Shout]! + topLayoutShouts(layout: String!, amount: Int, offset: Int): [Shout]! + recentLayoutShouts(layout: String!, amount: Int, offset: Int): [Shout]! + # reactons reactionsByAuthor(slug: String!, offset: Int!, limit: Int!): [Reaction]! reactionsForShouts(shouts: [String]!, offset: Int!, limit: Int!): [Reaction]!