Clean up the repository list API and loads stars with it
We load stars with the same list API now so that we get the extra metadata needed in the repo list (popularity and last modified)
This commit is contained in:
parent
bb269a56b6
commit
a0c4e72f13
7 changed files with 107 additions and 56 deletions
|
@ -147,6 +147,9 @@ def repository_is_starred(user, repository):
|
|||
|
||||
|
||||
def get_when_last_modified(repository_ids):
|
||||
if not repository_ids:
|
||||
return {}
|
||||
|
||||
tuples = (RepositoryTag
|
||||
.select(RepositoryTag.repository, fn.Max(RepositoryTag.lifetime_start_ts))
|
||||
.where(RepositoryTag.repository << repository_ids)
|
||||
|
@ -161,6 +164,9 @@ def get_when_last_modified(repository_ids):
|
|||
|
||||
|
||||
def get_action_counts(repository_ids):
|
||||
if not repository_ids:
|
||||
return {}
|
||||
|
||||
# Filter the join to recent entries only.
|
||||
last_week = datetime.now() - timedelta(weeks=1)
|
||||
tuples = (RepositoryActionCount
|
||||
|
@ -177,25 +183,26 @@ def get_action_counts(repository_ids):
|
|||
return action_count_map
|
||||
|
||||
|
||||
def get_visible_repositories(username=None, include_public=True, page=None,
|
||||
limit=None, namespace=None, namespace_only=False):
|
||||
def get_visible_repositories(username, namespace=None, page=None, limit=None, include_public=False):
|
||||
""" Returns the repositories visible to the given user (if any).
|
||||
"""
|
||||
if not include_public and not username:
|
||||
return []
|
||||
|
||||
fields = [Repository.name, Repository.id, Repository.description, Visibility.name,
|
||||
Namespace.username]
|
||||
|
||||
query = _visible_repository_query(username=username, include_public=include_public, page=page,
|
||||
limit=limit, namespace=namespace,
|
||||
query = _visible_repository_query(username=username, page=page,
|
||||
limit=limit, namespace=namespace, include_public=include_public,
|
||||
select_models=fields)
|
||||
|
||||
if limit:
|
||||
query = query.limit(limit)
|
||||
|
||||
if namespace and namespace_only:
|
||||
if namespace:
|
||||
query = query.where(Namespace.username == namespace)
|
||||
|
||||
return TupleSelector(query, fields)
|
||||
return query
|
||||
|
||||
|
||||
def _visible_repository_query(username=None, include_public=True, limit=None,
|
||||
|
|
Reference in a new issue