diff --git a/src/app/index/collection.rs b/src/app/index/collection.rs index b77aa182..713e9186 100644 --- a/src/app/index/collection.rs +++ b/src/app/index/collection.rs @@ -23,11 +23,12 @@ pub struct ArtistHeader { pub num_albums_as_composer: u32, pub num_albums_as_lyricist: u32, pub num_songs_by_genre: HashMap, + pub num_songs: u32, } #[derive(Debug, Default, PartialEq, Eq)] pub struct Artist { - pub header: ArtistHeader, + pub name: String, pub albums_as_performer: Vec, pub albums_as_additional_performer: Vec, // Albums where this artist shows up as `artist` without being `album_artist` pub albums_as_composer: Vec, @@ -104,7 +105,7 @@ impl Collection { let albums_as_lyricist = list_albums(&a.albums_as_lyricist); Artist { - header: make_artist_header(a, strings), + name: strings.resolve(&a.name).to_owned(), albums_as_performer, albums_as_additional_performer, albums_as_composer, @@ -183,6 +184,7 @@ fn make_artist_header(artist: &storage::Artist, strings: &RodeoReader) -> Artist .iter() .map(|(genre, num)| (strings.resolve(genre).to_string(), *num)) .collect(), + num_songs: artist.num_songs, } } @@ -269,6 +271,7 @@ impl Builder { for name in all_artists { let artist = self.get_or_create_artist(name); + artist.num_songs += 1; for genre in &song.genres { *artist .num_songs_by_genre @@ -290,6 +293,7 @@ impl Builder { albums_as_composer: HashSet::new(), albums_as_lyricist: HashSet::new(), num_songs_by_genre: HashMap::new(), + num_songs: 0, }) .borrow_mut() } diff --git a/src/app/index/storage.rs b/src/app/index/storage.rs index e79c88dc..8aeb1605 100644 --- a/src/app/index/storage.rs +++ b/src/app/index/storage.rs @@ -24,6 +24,7 @@ pub struct Artist { pub albums_as_composer: HashSet, pub albums_as_lyricist: HashSet, pub num_songs_by_genre: HashMap, + pub num_songs: u32, } #[derive(Clone, Debug, Default, Serialize, Deserialize)] @@ -114,7 +115,7 @@ pub fn store_song( let mut canonicalize = |s: &String| { minuscules - .entry(s.to_lowercase()) + .entry(s.trim().to_lowercase()) .or_insert_with(|| strings.get_or_intern(s)) .to_owned() }; diff --git a/src/server/dto/v8.rs b/src/server/dto/v8.rs index e38c50f1..a7a8452d 100644 --- a/src/server/dto/v8.rs +++ b/src/server/dto/v8.rs @@ -325,6 +325,7 @@ pub struct ArtistHeader { pub num_albums_as_composer: u32, pub num_albums_as_lyricist: u32, pub num_songs_by_genre: HashMap, + pub num_songs: u32, } impl From for ArtistHeader { @@ -336,14 +337,14 @@ impl From for ArtistHeader { num_albums_as_composer: a.num_albums_as_composer, num_albums_as_lyricist: a.num_albums_as_lyricist, num_songs_by_genre: a.num_songs_by_genre, + num_songs: a.num_songs, } } } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Artist { - #[serde(flatten)] - pub header: ArtistHeader, + pub name: String, pub albums_as_performer: Vec, pub albums_as_additional_performer: Vec, pub albums_as_composer: Vec, @@ -354,7 +355,7 @@ impl From for Artist { fn from(a: index::Artist) -> Self { let convert_albums = |a: Vec| a.into_iter().map(|a| a.into()).collect(); Self { - header: a.header.into(), + name: a.name, albums_as_performer: convert_albums(a.albums_as_performer), albums_as_additional_performer: convert_albums(a.albums_as_additional_performer), albums_as_composer: convert_albums(a.albums_as_composer),