From 32255f122b14c92418b950fd2b179f97a8a31b87 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 30 Nov 2017 16:56:01 -0500 Subject: [PATCH] Simplify and further optimize handling of unfiltered search results Using the DB-side limit is much faster --- data/model/repository.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/data/model/repository.py b/data/model/repository.py index 7c60c7dc7..2d7970e82 100644 --- a/data/model/repository.py +++ b/data/model/repository.py @@ -428,10 +428,6 @@ def get_app_search(lookup, search_fields=None, username=None, limit=50): offset=0, limit=limit) -def _iterator_wrap(query): - for row in query: - yield row - def get_filtered_matching_repositories(lookup_value, filter_username=None, repo_kind='image', offset=0, limit=25, search_fields=None): """ Returns an iterator of all repositories matching the given lookup value, with optional @@ -451,14 +447,13 @@ def get_filtered_matching_repositories(lookup_value, filter_username=None, repo_ if filter_username is not None: iterator = _filter_repositories_visible_to_username(unfiltered_query, filter_username, limit, repo_kind) - else: - iterator = _iterator_wrap(unfiltered_query) + if offset > 0: + take(offset, iterator) - if offset > 0: - take(offset, iterator) + # Return the results. + return list(take(limit, iterator)) - # Return the results. - return list(take(limit, iterator)) + return list(unfiltered_query.offset(offset).limit(limit)) def _filter_repositories_visible_to_username(unfiltered_query, filter_username, limit, repo_kind):