Prettify code
Some checks failed
Cargo CI / Build and Test (pull_request) Successful in 2m1s
Cargo CI / Lint (pull_request) Failing after 28s

This commit is contained in:
Wojciech Kozlowski 2025-01-02 15:14:11 +01:00
parent 8a1447334e
commit 38fa7f82c6
2 changed files with 13 additions and 28 deletions

View File

@ -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);
}
}

View File

@ -61,32 +61,26 @@ impl Artist {
primary_albums: &mut [Album],
mut secondary_album: Album,
) -> Option<Album> {
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<Album>,
) -> HashMap<String, Vec<Album>> {
let mut secondary_without_id = HashMap::<String, Vec<Album>>::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<Album>,
mut secondary_without_id: HashMap<String, Vec<Album>>,
) {
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();
}
}