Startup merge fails when the database has two albums with the same title as an album in the library #246
@ -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>,
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user