WIP: Refactor the IDatabase calls to write directly to the database #271
@ -170,15 +170,10 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
||||
album_id: AlbumIdRef,
|
||||
mut info: AlbumInfo,
|
||||
) -> Result<(), Error> {
|
||||
self.update_album_and(
|
||||
artist_id.as_ref(),
|
||||
album_id.as_ref(),
|
||||
|album| {
|
||||
self.update_album_and_sort(artist_id.as_ref(), album_id.as_ref(), |album| {
|
||||
mem::swap(&mut album.meta.info, &mut info);
|
||||
album.meta.info.merge_in_place(info);
|
||||
},
|
||||
|artist| artist.albums.sort_unstable(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn clear_album_info<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
|
||||
@ -186,12 +181,9 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
||||
artist_id: Id,
|
||||
album_id: AlbumIdRef,
|
||||
) -> Result<(), Error> {
|
||||
self.update_album_and(
|
||||
artist_id.as_ref(),
|
||||
album_id.as_ref(),
|
||||
|album| album.meta.info = AlbumInfo::default(),
|
||||
|artist| artist.albums.sort_unstable(),
|
||||
)
|
||||
self.update_album_and_sort(artist_id.as_ref(), album_id.as_ref(), |album| {
|
||||
album.meta.info = AlbumInfo::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,6 +262,20 @@ impl<Database: IDatabase, Library> MusicHoard<Database, Library> {
|
||||
self.update_collection(|_| {})
|
||||
}
|
||||
|
||||
fn update_album_and_sort<FnAlbum>(
|
||||
&mut self,
|
||||
artist_id: &ArtistId,
|
||||
album_id: &AlbumId,
|
||||
fn_album: FnAlbum,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
FnAlbum: FnOnce(&mut Album),
|
||||
{
|
||||
self.update_album_and(artist_id, album_id, fn_album, |artist| {
|
||||
artist.albums.sort_unstable()
|
||||
})
|
||||
}
|
||||
|
||||
fn update_album<FnAlbum>(
|
||||
&mut self,
|
||||
artist_id: &ArtistId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user