WIP: Refactor the IDatabase calls to write directly to the database #271
@ -30,7 +30,6 @@ impl<Database, Library> IMusicHoardBase for MusicHoard<Database, Library> {
|
||||
}
|
||||
|
||||
pub trait IMusicHoardBasePrivate {
|
||||
fn sort_artists(collection: &mut [Artist]);
|
||||
fn sort_albums_and_tracks<'a, C: Iterator<Item = &'a mut Artist>>(collection: C);
|
||||
|
||||
fn merge_collections<It: IntoIterator<Item = Artist>>(&self, database: It) -> Collection;
|
||||
@ -55,10 +54,6 @@ pub trait IMusicHoardBasePrivate {
|
||||
}
|
||||
|
||||
impl<Database, Library> IMusicHoardBasePrivate for MusicHoard<Database, Library> {
|
||||
fn sort_artists(collection: &mut [Artist]) {
|
||||
collection.sort_unstable();
|
||||
}
|
||||
|
||||
fn sort_albums_and_tracks<'a, COL: Iterator<Item = &'a mut Artist>>(collection: COL) {
|
||||
for artist in collection {
|
||||
artist.albums.sort_unstable();
|
||||
|
@ -86,19 +86,11 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
||||
artist_id: Id,
|
||||
mb_ref: ArtistMbRef,
|
||||
) -> Result<(), Error> {
|
||||
self.update_artist_and(
|
||||
artist_id.as_ref(),
|
||||
|artist| artist.meta.set_mb_ref(mb_ref),
|
||||
|collection| Self::sort_artists(collection),
|
||||
)
|
||||
self.update_artist(artist_id.as_ref(), |artist| artist.meta.set_mb_ref(mb_ref))
|
||||
}
|
||||
|
||||
fn clear_artist_mb_ref<Id: AsRef<ArtistId>>(&mut self, artist_id: Id) -> Result<(), Error> {
|
||||
self.update_artist_and(
|
||||
artist_id.as_ref(),
|
||||
|artist| artist.meta.clear_mb_ref(),
|
||||
|collection| Self::sort_artists(collection),
|
||||
)
|
||||
self.update_artist(artist_id.as_ref(), |artist| artist.meta.clear_mb_ref())
|
||||
}
|
||||
|
||||
fn merge_artist_info<Id: AsRef<ArtistId>>(
|
||||
@ -157,12 +149,9 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
||||
album_id: AlbumIdRef,
|
||||
mb_ref: AlbumMbRef,
|
||||
) -> Result<(), Error> {
|
||||
self.update_album_and(
|
||||
artist_id.as_ref(),
|
||||
album_id.as_ref(),
|
||||
|album| album.meta.set_mb_ref(mb_ref),
|
||||
|artist| artist.albums.sort_unstable(),
|
||||
)
|
||||
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
|
||||
album.meta.set_mb_ref(mb_ref)
|
||||
})
|
||||
}
|
||||
|
||||
fn clear_album_mb_ref<ArtistIdRef: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
|
||||
@ -170,12 +159,9 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
||||
artist_id: ArtistIdRef,
|
||||
album_id: AlbumIdRef,
|
||||
) -> Result<(), Error> {
|
||||
self.update_album_and(
|
||||
artist_id.as_ref(),
|
||||
album_id.as_ref(),
|
||||
|album| album.meta.clear_mb_ref(),
|
||||
|artist| artist.albums.sort_unstable(),
|
||||
)
|
||||
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
|
||||
album.meta.clear_mb_ref()
|
||||
})
|
||||
}
|
||||
|
||||
fn merge_album_info<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
|
||||
@ -184,10 +170,15 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
||||
album_id: AlbumIdRef,
|
||||
mut info: AlbumInfo,
|
||||
) -> Result<(), Error> {
|
||||
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
|
||||
self.update_album_and(
|
||||
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>>(
|
||||
@ -195,9 +186,12 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
||||
artist_id: Id,
|
||||
album_id: AlbumIdRef,
|
||||
) -> Result<(), Error> {
|
||||
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
|
||||
album.meta.info = AlbumInfo::default()
|
||||
})
|
||||
self.update_album_and(
|
||||
artist_id.as_ref(),
|
||||
album_id.as_ref(),
|
||||
|album| album.meta.info = AlbumInfo::default(),
|
||||
|artist| artist.albums.sort_unstable(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user