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.