refactoring-wip

This commit is contained in:
tonyrewin 2022-11-13 12:25:02 +03:00
parent 12bbc2a316
commit 2e705fa2c9
2 changed files with 18 additions and 3 deletions

View File

@ -125,8 +125,12 @@ async def shouts_by_authors(_, _info, slugs, offset=0, limit=100):
return shouts_prepared[offset : offset + limit] return shouts_prepared[offset : offset + limit]
@query.field("shoutsByLayout") @query.field("recentLayoutShouts")
async def shouts_by_layout(_, _info, layout, amount=100, offset=0): @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: async with ShoutsCache.lock:
shouts = {} shouts = {}
# for layout in ['image', 'audio', 'video', 'literature']: # 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): # if bool(s.publishedAt):
shouts[s.slug] = s shouts[s.slug] = s
shouts_prepared = list(shouts.values()) 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] return shouts_prepared[offset : offset + amount]

View File

@ -261,6 +261,11 @@ type Query {
recentAll(offset: Int!, limit: Int!): [Shout]! recentAll(offset: Int!, limit: Int!): [Shout]!
recentCandidates(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 # reactons
reactionsByAuthor(slug: String!, offset: Int!, limit: Int!): [Reaction]! reactionsByAuthor(slug: String!, offset: Int!, limit: Int!): [Reaction]!
reactionsForShouts(shouts: [String]!, offset: Int!, limit: Int!): [Reaction]! reactionsForShouts(shouts: [String]!, offset: Int!, limit: Int!): [Reaction]!