From 9d97e053b3384adc12f3435c2f4fec611c5ca41c Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 3 May 2017 18:38:46 -0400 Subject: [PATCH] Make sure to re-sort the filtered repositories in search The filtering breaks the ordered we expected, so we need to re-sort --- data/model/repository.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data/model/repository.py b/data/model/repository.py index 1b113fe42..e94b8b4fa 100644 --- a/data/model/repository.py +++ b/data/model/repository.py @@ -464,7 +464,13 @@ def _filter_repositories_visible_to_username(unfiltered_query, filter_username, .where(Repository.id << list(new_unfiltered_ids))) filtered = _basequery.filter_to_repos_for_user(query, filter_username, repo_kind=repo_kind) - for filtered_repo in filtered: + + # Sort the filtered repositories by their initial order. + all_filtered_repos = list(filtered) + all_filtered_repos.sort(key=lambda repo: found_ids.index(repo.id)) + + # Yield the repositories in sorted order. + for filtered_repo in all_filtered_repos: yield filtered_repo # If the number of found IDs is less than the chunk count, then we're done.