diff --git a/src/cli/search.rs b/src/cli/search.rs index 3cb069e24..43dc47600 100644 --- a/src/cli/search.rs +++ b/src/cli/search.rs @@ -54,30 +54,30 @@ where repo.package_names() .filter(|&name| filter_func(name, package)) }) + .unique() .collect::>(); let mut latest_packages = Vec::new(); // search for `similar_packages` in all platform's repodata // add the latest version of the fetched package to latest_packages vector - for repo in repo_data.values() { - for package in &similar_packages { - let mut records = repo - .load_records(&PackageName::new_unchecked(*package)) - .into_diagnostic()?; - // sort records by version, get the latest one - records.sort_by(|a, b| a.package_record.version.cmp(&b.package_record.version)); - let latest_package = records.last().cloned(); - if let Some(latest_package) = latest_package { - latest_packages.push(latest_package); - } + for package in similar_packages { + let mut records = Vec::new(); + + for repo in repo_data.values() { + records.extend( + repo.load_records(&PackageName::new_unchecked(package)) + .into_diagnostic()?, + ); } - } - latest_packages = latest_packages - .into_iter() - .unique_by(|record| record.package_record.name.clone()) - .collect::>(); + // sort records by version, get the latest one + records.sort_by(|a, b| a.package_record.version.cmp(&b.package_record.version)); + let latest_package = records.last().cloned(); + if let Some(latest_package) = latest_package { + latest_packages.push(latest_package); + } + } Ok(latest_packages) }