Ensure consistency between in-memory and database state #146

Merged
wojtek merged 8 commits from 120---ensure-consistency-between-in-memory-and-database-state into main 2024-03-01 09:00:53 +01:00
Showing only changes of commit 1dcd701acf - Show all commits

View File

@ -81,8 +81,11 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
primary.insert(secondary_artist.id.clone(), secondary_artist);
}
}
self.collection = primary.into_values().collect();
Self::sort_artists(&mut self.collection);
self.pre_commit = self.collection.clone();
}
fn items_to_artists(items: Vec<Item>) -> Result<HashMap<ArtistId, Artist>, Error> {
@ -176,7 +179,7 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
}
impl<LIB: ILibrary> MusicHoard<LIB, NoDatabase> {
/// Create a new [`MusicHoard`] with the provided [`IDatabase`].
/// Create a new [`MusicHoard`] with the provided [`ILibrary`] and no database.
pub fn library(library: LIB) -> Self {
MusicHoard {
collection: vec![],
@ -202,7 +205,7 @@ impl<LIB: ILibrary, DB> MusicHoard<LIB, DB> {
}
impl<DB: IDatabase> MusicHoard<NoLibrary, DB> {
/// Create a new [`MusicHoard`] with the provided [`IDatabase`].
/// Create a new [`MusicHoard`] with the provided [`IDatabase`] and no library.
pub fn database(database: DB) -> Result<Self, Error> {
let mut mh = MusicHoard {
collection: vec![],
@ -224,8 +227,6 @@ impl<LIB, DB: IDatabase> MusicHoard<LIB, DB> {
Self::sort_albums_and_tracks(self.database_cache.iter_mut());
self.merge_collections();
self.pre_commit = self.collection.clone();
Ok(())
}