Startup merge fails when the database has two albums with the same title as an album in the library #246

Merged
wojtek merged 11 commits from 245---startup-merge-fails-when-the-database-has-two-albums-with-the-same-title-as-an-album-in-the-library into main 2025-01-03 17:46:55 +01:00
3 changed files with 12 additions and 12 deletions
Showing only changes of commit e723507897 - Show all commits

View File

@ -6,7 +6,7 @@ use std::{
use crate::core::collection::{
album::{Album, AlbumLibId},
merge::{Merge, MergeCollections, TitleMap},
merge::{Merge, MergeCollections, NormalMap},
musicbrainz::{MbArtistRef, MbRefOption},
string::{self, NormalString},
};
@ -65,8 +65,8 @@ impl Merge for Artist {
struct MergeAlbums {
primary_by_lib_id: HashMap<u32, Album>,
primary_by_singleton: HashMap<NormalString, Album>,
primary_by_title: TitleMap<Album>,
secondary_by_title: TitleMap<Album>,
primary_by_title: NormalMap<Album>,
secondary_by_title: NormalMap<Album>,
merged: Vec<Album>,
}

View File

@ -83,17 +83,17 @@ where
}
#[derive(Debug)]
pub struct TitleMap<T>(HashMap<NormalString, Vec<T>>);
pub struct NormalMap<T>(HashMap<NormalString, Vec<T>>);
impl<T> Default for TitleMap<T> {
impl<T> Default for NormalMap<T> {
fn default() -> Self {
TitleMap(HashMap::default())
NormalMap(HashMap::default())
}
}
impl<T> TitleMap<T> {
impl<T> NormalMap<T> {
pub fn new() -> Self {
TitleMap(HashMap::new())
NormalMap(HashMap::new())
}
pub fn insert(&mut self, key: NormalString, item: T) {
@ -108,7 +108,7 @@ impl<T> TitleMap<T> {
pub struct MergeCollections;
impl MergeCollections {
pub fn merge_by_name<T: Merge>(mut primary: TitleMap<T>, secondary: TitleMap<T>) -> Vec<T> {
pub fn merge_by_name<T: Merge>(mut primary: NormalMap<T>, secondary: NormalMap<T>) -> Vec<T> {
let mut merged = vec![];
for (title, mut secondary_items) in secondary.0.into_iter() {
match primary.remove(&title) {

View File

@ -2,7 +2,7 @@ use crate::core::{
collection::{
album::{Album, AlbumId},
artist::{Artist, ArtistId},
merge::{MergeCollections, TitleMap},
merge::{MergeCollections, NormalMap},
string, Collection,
},
musichoard::{Error, MusicHoard},
@ -57,8 +57,8 @@ impl<Database, Library> IMusicHoardBasePrivate for MusicHoard<Database, Library>
}
fn merge_collections(&self) -> Collection {
let mut primary = TitleMap::<Artist>::new();
let mut secondary = TitleMap::<Artist>::new();
let mut primary = NormalMap::<Artist>::new();
let mut secondary = NormalMap::<Artist>::new();
for artist in self.library_cache.iter().cloned() {
primary.insert(string::normalize_string(&artist.meta.id.name), artist);