diff --git a/src/core/collection/album.rs b/src/core/collection/album.rs index b402008..da49982 100644 --- a/src/core/collection/album.rs +++ b/src/core/collection/album.rs @@ -269,9 +269,7 @@ impl Ord for AlbumMeta { impl Merge for AlbumMeta { fn merge_in_place(&mut self, other: Self) { assert!(self.id.compatible(&other.id)); - self.seq = std::cmp::max(self.seq, other.seq); - self.info.merge_in_place(other.info); } } diff --git a/src/core/collection/artist.rs b/src/core/collection/artist.rs index 396561b..71bf781 100644 --- a/src/core/collection/artist.rs +++ b/src/core/collection/artist.rs @@ -61,32 +61,26 @@ impl Artist { primary_albums: &mut [Album], mut secondary_album: Album, ) -> Option { - if let lib_id @ AlbumLibId::Value(_) | lib_id @ AlbumLibId::Singleton = - secondary_album.meta.id.lib_id - { - if let Some(ref mut primary_album) = primary_albums - .iter_mut() - .find(|album| album.meta.id.lib_id == lib_id) - { + let id_opt = secondary_album.meta.id.lib_id; + if let id @ AlbumLibId::Value(_) | id @ AlbumLibId::Singleton = id_opt { + let mut iter = primary_albums.iter_mut(); + if let Some(ref mut primary_album) = iter.find(|a| a.meta.id.lib_id == id) { primary_album.merge_in_place(secondary_album); return None; } - secondary_album.meta.id.lib_id = AlbumLibId::None; } - Some(secondary_album) } - fn merge_albums_with_lib_id( + fn merge_albums_by_lib_id( primary_albums: &mut [Album], mut secondary_albums: Vec, ) -> HashMap> { let mut secondary_without_id = HashMap::>::new(); for secondary_album in secondary_albums.drain(..) { - if let Some(secondary_album) = - Artist::merge_album_with_lib_id(primary_albums, secondary_album) - { + let unmerged = Artist::merge_album_with_lib_id(primary_albums, secondary_album); + if let Some(secondary_album) = unmerged { secondary_without_id .entry(secondary_album.meta.id.title.clone()) .or_default() @@ -96,15 +90,13 @@ impl Artist { secondary_without_id } - fn merge_albums_with_title( + fn merge_albums_by_title( primary_albums: &mut Vec, mut secondary_without_id: HashMap>, ) { for (title, mut secondary_albums) in secondary_without_id.drain() { - match primary_albums - .iter_mut() - .find(|album| album.meta.id.title == title) - { + let mut iter = primary_albums.iter_mut(); + match iter.find(|album| album.meta.id.title == title) { Some(ref mut primary_album) => { // We do not support merging multiple DB albums with same title yet. assert_eq!(secondary_albums.len(), 1); @@ -132,15 +124,10 @@ impl Merge for Artist { fn merge_in_place(&mut self, other: Self) { self.meta.merge_in_place(other.meta); - let mut primary_albums = mem::take(&mut self.albums); - let secondary_albums = other.albums; + let other_without_id = Artist::merge_albums_by_lib_id(&mut self.albums, other.albums); + Artist::merge_albums_by_title(&mut self.albums, other_without_id); - let secondary_without_id = - Artist::merge_albums_with_lib_id(&mut primary_albums, secondary_albums); - Artist::merge_albums_with_title(&mut primary_albums, secondary_without_id); - - primary_albums.sort_unstable(); - self.albums = primary_albums; + self.albums.sort_unstable(); } }