Merge pull request #2529 from coreos-inc/search-ui

Implement new search UI
This commit is contained in:
josephschorr 2017-05-02 15:56:59 -04:00 committed by GitHub
commit 5a9a231754
23 changed files with 649 additions and 393 deletions

View file

@ -42,10 +42,11 @@ def filter_to_repos_for_user(query, username=None, namespace=None, repo_kind='im
return Repository.select().where(Repository.id == '-1')
# Filter on the type of repository.
try:
query = query.where(Repository.kind == Repository.kind.get_id(repo_kind))
except RepositoryKind.DoesNotExist:
raise DataModelException('Unknown repository kind')
if repo_kind is not None:
try:
query = query.where(Repository.kind == Repository.kind.get_id(repo_kind))
except RepositoryKind.DoesNotExist:
raise DataModelException('Unknown repository kind')
# Add the start ID if necessary.
if start_id is not None:

View file

@ -318,6 +318,9 @@ def repository_is_starred(user, repository):
def get_when_last_modified(repository_ids):
""" Returns a map from repository ID to the last modified time (in s) for each repository in the
given repository IDs list.
"""
if not repository_ids:
return {}
@ -334,6 +337,26 @@ def get_when_last_modified(repository_ids):
return last_modified_map
def get_stars(repository_ids):
""" Returns a map from repository ID to the number of stars for each repository in the
given repository IDs list.
"""
if not repository_ids:
return {}
tuples = (Star
.select(Star.repository, fn.Count(Star.id))
.where(Star.repository << repository_ids)
.group_by(Star.repository)
.tuples())
star_map = {}
for record in tuples:
star_map[record[0]] = record[1]
return star_map
def get_visible_repositories(username, namespace=None, kind_filter='image', include_public=False,
start_id=None, limit=None):
""" Returns the repositories visible to the given user (if any).
@ -471,10 +494,12 @@ def _get_sorted_matching_repositories(lookup_value, repo_kind='image', include_p
query = (Repository
.select(Repository, Namespace)
.join(Namespace, on=(Namespace.id == Repository.namespace_user))
.where(clause,
Repository.kind == Repository.kind.get_id(repo_kind))
.where(clause)
.group_by(Repository.id, Namespace.id))
if repo_kind is not None:
query = query.where(Repository.kind == Repository.kind.get_id(repo_kind))
if not include_private:
query = query.where(Repository.visibility == _basequery.get_public_repo_visibility())