Fix pagination of public repos, make more efficient and add test

This commit is contained in:
Joseph Schorr 2016-08-10 15:08:06 -04:00
parent bf34916b26
commit 4a2acac5dc
3 changed files with 39 additions and 17 deletions

View file

@ -26,11 +26,13 @@ def paginate(query, model, descending=False, page_token=None, limit=50, id_alias
query = query.where(model.id <= start_id)
else:
query = query.where(model.id >= start_id)
else:
query = query.limit(limit + 1)
results = list(query)
page_token = None
if len(results) > limit:
start_id = results[limit].id
start_id = getattr(results[limit], id_alias or 'id')
page_token = {
'start_id': start_id
}