From eece7820382ebec71a47f8c4ae3f7709869ef3fd Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 17 Feb 2017 12:09:48 -0500 Subject: [PATCH 1/2] Prevent peewee from loading the visibility every time By calling `visibility` instead of `visibility_id`, peewee was issuing a SQL Select statement for the repository, which removes the benefit of the optimization --- data/model/repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/model/repository.py b/data/model/repository.py index 910ae358a..6709b3f09 100644 --- a/data/model/repository.py +++ b/data/model/repository.py @@ -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): From a319c55616169e8b168dd8de2cd3f8926f65870d Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 17 Feb 2017 12:22:21 -0500 Subject: [PATCH 2/2] Don't make permissions request in search for public callers They are unnecessary, so we can skip them --- endpoints/v1/index.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/endpoints/v1/index.py b/endpoints/v1/index.py index c9a4c72dd..f70b77f5c 100644 --- a/endpoints/v1/index.py +++ b/endpoints/v1/index.py @@ -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)