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 7 additions and 2 deletions
Showing only changes of commit 7cf77c74cc - Show all commits

View File

@ -6,6 +6,8 @@ use crate::core::collection::{
track::{Track, TrackFormat}, track::{Track, TrackFormat},
}; };
use super::string;
/// An album is a collection of tracks that were released together. /// An album is a collection of tracks that were released together.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Album { pub struct Album {
@ -314,7 +316,8 @@ impl AlbumId {
} }
pub fn compatible(&self, other: &AlbumId) -> bool { pub fn compatible(&self, other: &AlbumId) -> bool {
let titles_compatible = self.title == other.title; let titles_compatible =
string::normalize_string(&self.title) == string::normalize_string(&other.title);
let lib_id_compatible = let lib_id_compatible =
self.lib_id.is_none() || other.lib_id.is_none() || (self.lib_id == other.lib_id); self.lib_id.is_none() || other.lib_id.is_none() || (self.lib_id == other.lib_id);
let mb_ref_compatible = let mb_ref_compatible =

View File

@ -285,7 +285,8 @@ impl ArtistId {
} }
pub fn compatible(&self, other: &ArtistId) -> bool { pub fn compatible(&self, other: &ArtistId) -> bool {
let names_compatible = self.name == other.name; let names_compatible =
string::normalize_string(&self.name) == string::normalize_string(&other.name);
let mb_ref_compatible = let mb_ref_compatible =
self.mb_ref.is_none() || other.mb_ref.is_none() || (self.mb_ref == other.mb_ref); self.mb_ref.is_none() || other.mb_ref.is_none() || (self.mb_ref == other.mb_ref);
names_compatible && mb_ref_compatible names_compatible && mb_ref_compatible

View File

@ -54,6 +54,7 @@ pub fn normalize_string(string: &str) -> NormalString {
#[cfg(test)] #[cfg(test)]
mod benches { mod benches {
// The purpose of these benches was to evaluate the benefit of AhoCorasick over std solutions. // The purpose of these benches was to evaluate the benefit of AhoCorasick over std solutions.
// The winners are left to allow comparison with future alternatives.
use test::Bencher; use test::Bencher;
use crate::core::collection::benchmod::ARTISTS; use crate::core::collection::benchmod::ARTISTS;