Fix duplicates issue with local version cache

feature/lookup-installed
trivernis 2 years ago
parent 97a6ee5a60
commit 0e47ee75e7
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -17,6 +17,7 @@ pub struct InstalledVersions {
impl InstalledVersions {
pub fn new(mut versions: Vec<(SimpleVersion, VersionMetadata)>) -> Self {
versions.sort_by_key(|e| e.0);
versions.dedup_by_key(|e| e.0);
Self {
ordered_versions: versions,
}
@ -53,6 +54,7 @@ impl InstalledVersions {
pub fn insert(&mut self, version: (SimpleVersion, VersionMetadata)) {
self.ordered_versions.push(version);
self.ordered_versions.sort_by_key(|e| e.0);
self.ordered_versions.dedup_by_key(|e| e.0);
}
/// Removes a version. This keeps the order intact

@ -104,9 +104,14 @@ impl Repository {
let installed_versions = match InstalledVersions::load() {
Ok(v) => v,
Err(_) => load_installed_versions_info(downloader.versions().await?)
Err(_) => {
let installed: InstalledVersions =
load_installed_versions_info(downloader.versions().await?)
.await?
.into(),
.into();
installed.save()?;
installed
}
};
Ok(Self {

Loading…
Cancel
Save