add top shouts pagination
This commit is contained in:
parent
e3bc1c0c38
commit
e368ebf4e9
|
@ -6,24 +6,23 @@ import importlib
|
||||||
from migration.utils import DateTimeEncoder
|
from migration.utils import DateTimeEncoder
|
||||||
|
|
||||||
def json_tables():
|
def json_tables():
|
||||||
print('creating json files at migration/data/')
|
print('creating json files at migration/data/')
|
||||||
data = {
|
data = {
|
||||||
"content_items": [],
|
"content_items": [],
|
||||||
"content_item_categories": [],
|
"content_item_categories": [],
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"email_subscriptions": [],
|
"email_subscriptions": [],
|
||||||
"users": [],
|
"users": [],
|
||||||
"comments": []
|
"comments": []
|
||||||
}
|
}
|
||||||
for table in data.keys():
|
for table in data.keys():
|
||||||
lc = []
|
lc = []
|
||||||
with open('migration/data/'+table+'.bson', 'rb') as f:
|
with open('migration/data/'+table+'.bson', 'rb') as f:
|
||||||
bs = f.read()
|
bs = f.read()
|
||||||
base = 0
|
base = 0
|
||||||
while base < len(bs):
|
while base < len(bs):
|
||||||
base, d = bson.decode_document(bs, base)
|
base, d = bson.decode_document(bs, base)
|
||||||
lc.append(d)
|
lc.append(d)
|
||||||
data[table] = lc
|
data[table] = lc
|
||||||
open('migration/data/'+table+'.json', 'w').write(json.dumps(lc,cls=DateTimeEncoder))
|
open('migration/data/'+table+'.json', 'w').write(json.dumps(lc,cls=DateTimeEncoder))
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
|
@ -191,24 +191,24 @@ class ShoutSubscriptions:
|
||||||
subs.put_nowait(shout)
|
subs.put_nowait(shout)
|
||||||
|
|
||||||
@query.field("topViewed")
|
@query.field("topViewed")
|
||||||
async def top_viewed(_, info, limit):
|
async def top_viewed(_, info, page, size):
|
||||||
async with ShoutsCache.lock:
|
async with ShoutsCache.lock:
|
||||||
return ShoutsCache.top_viewed[:limit]
|
return ShoutsCache.top_viewed[page * size : (page + 1) * size]
|
||||||
|
|
||||||
@query.field("topMonth")
|
@query.field("topMonth")
|
||||||
async def top_month(_, info, limit):
|
async def top_month(_, info, page, size):
|
||||||
async with ShoutsCache.lock:
|
async with ShoutsCache.lock:
|
||||||
return ShoutsCache.top_month[:limit]
|
return ShoutsCache.top_month[page * size : (page + 1) * size]
|
||||||
|
|
||||||
@query.field("topOverall")
|
@query.field("topOverall")
|
||||||
async def top_overall(_, info, limit):
|
async def top_overall(_, info, page, size):
|
||||||
async with ShoutsCache.lock:
|
async with ShoutsCache.lock:
|
||||||
return ShoutsCache.top_overall[:limit]
|
return ShoutsCache.top_overall[page * size : (page + 1) * size]
|
||||||
|
|
||||||
@query.field("recents")
|
@query.field("recents")
|
||||||
async def recent_shouts(_, info, limit):
|
async def recent_shouts(_, info, page, size):
|
||||||
async with ShoutsCache.lock:
|
async with ShoutsCache.lock:
|
||||||
return ShoutsCache.recent_shouts[:limit]
|
return ShoutsCache.recent_shouts[page * size : (page + 1) * size]
|
||||||
|
|
||||||
@mutation.field("createShout")
|
@mutation.field("createShout")
|
||||||
@login_required
|
@login_required
|
||||||
|
|
|
@ -160,10 +160,10 @@ type Query {
|
||||||
getShoutComments(slug: String!): [Comment]!
|
getShoutComments(slug: String!): [Comment]!
|
||||||
|
|
||||||
# mainpage
|
# mainpage
|
||||||
topViewed(limit: Int): [Shout]!
|
topViewed(page: Int!, size: Int!): [Shout]!
|
||||||
topMonth(limit: Int): [Shout]!
|
topMonth(page: Int!, size: Int!): [Shout]!
|
||||||
topOverall(limit: Int): [Shout]!
|
topOverall(page: Int!, size: Int!): [Shout]!
|
||||||
recents(limit: Int): [Shout]!
|
recents(page: Int!, size: Int!): [Shout]!
|
||||||
|
|
||||||
# topics
|
# topics
|
||||||
topicsBySlugs(slugs: [String]): [Topic]!
|
topicsBySlugs(slugs: [String]): [Topic]!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user