Fix popularity metrics on list repos API
This commit is contained in:
parent
6bde6406c9
commit
e252ee07cb
4 changed files with 18 additions and 11 deletions
|
@ -15,15 +15,15 @@ def paginate(query, model, descending=False, page_token=None, limit=50, id_field
|
|||
start_id = page_token.get('start_id')
|
||||
if start_id is not None:
|
||||
if descending:
|
||||
query = query.where(model.id <= start_id)
|
||||
query = query.where(getattr(model, id_field) <= start_id)
|
||||
else:
|
||||
query = query.where(model.id >= start_id)
|
||||
query = query.where(getattr(model, id_field) >= start_id)
|
||||
|
||||
results = list(query)
|
||||
page_token = None
|
||||
if len(results) > limit:
|
||||
page_token = {
|
||||
'start_id': results[limit].id
|
||||
'start_id': getattr(results[limit], id_field)
|
||||
}
|
||||
|
||||
return results[0:limit], page_token
|
||||
|
|
Reference in a new issue