Merge pull request #2363 from coreos-inc/opt-search

Small search query optimizations
This commit is contained in:
josephschorr 2017-02-18 13:51:12 -05:00 committed by GitHub
commit 2ef55a5842
2 changed files with 6 additions and 3 deletions

View file

@ -393,7 +393,7 @@ def lookup_repository(repo_id):
def is_repository_public(repository):
return repository.visibility == _basequery.get_public_repo_visibility()
return repository.visibility_id == _basequery.get_public_repo_visibility().id
def repository_is_public(namespace_name, repository_name):

View file

@ -312,10 +312,15 @@ def get_search():
def _conduct_repo_search(username, query, limit=25, page=1):
""" Finds matching repositories. """
only_public = username is None
def can_read(repo):
if repo.is_public:
return True
if only_public:
return False
return ReadRepositoryPermission(repo.namespace_user.username, repo.name).can()
# Note: We put a max 5 page limit here. The Docker CLI doesn't seem to use the
@ -326,8 +331,6 @@ def _conduct_repo_search(username, query, limit=25, page=1):
_MAX_PAGE_COUNT = 5
page = min(page, _MAX_PAGE_COUNT)
only_public = username is None
if query:
matching_repos = model.get_sorted_matching_repositories(query, only_public, can_read,
limit=limit*_MAX_PAGE_COUNT)