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
|
||||
|
|
|
@ -187,7 +187,7 @@ def unstar_repository(user, repository):
|
|||
def get_user_starred_repositories(user):
|
||||
""" Retrieves all of the repositories a user has starred. """
|
||||
query = (Repository
|
||||
.select(Repository, User, Visibility)
|
||||
.select(Repository, User, Visibility, Repository.id.alias('rid'))
|
||||
.join(Star)
|
||||
.switch(Repository)
|
||||
.join(User)
|
||||
|
@ -233,11 +233,11 @@ def get_visible_repositories(username, namespace=None, include_public=False):
|
|||
if not include_public and not username:
|
||||
# Short circuit by returning a query that will find no repositories. We need to return a query
|
||||
# here, as it will be modified by other queries later on.
|
||||
return Repository.select().where(Repository.id == -1)
|
||||
return Repository.select(Repository.id.alias('rid')).where(Repository.id == -1)
|
||||
|
||||
query = (Repository
|
||||
.select(Repository.name, Repository.id.alias('rid'), Repository.description, Namespace.username,
|
||||
Repository.visibility)
|
||||
.select(Repository.name, Repository.id.alias('rid'),
|
||||
Repository.description, Namespace.username, Repository.visibility)
|
||||
.distinct()
|
||||
.switch(Repository)
|
||||
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
|
||||
|
|
Reference in a new issue