Skip to content

Commit

Permalink
Track num songs by artist
Browse files Browse the repository at this point in the history
  • Loading branch information
agersant committed Sep 7, 2024
1 parent 07324cc commit e0bf259
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/app/index/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, u32>,
pub num_songs: u32,
}

#[derive(Debug, Default, PartialEq, Eq)]
pub struct Artist {
pub header: ArtistHeader,
pub name: String,
pub albums_as_performer: Vec<Album>,
pub albums_as_additional_performer: Vec<Album>, // Albums where this artist shows up as `artist` without being `album_artist`
pub albums_as_composer: Vec<Album>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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()
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/index/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct Artist {
pub albums_as_composer: HashSet<AlbumKey>,
pub albums_as_lyricist: HashSet<AlbumKey>,
pub num_songs_by_genre: HashMap<Spur, u32>,
pub num_songs: u32,
}

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -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()
};
Expand Down
7 changes: 4 additions & 3 deletions src/server/dto/v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, u32>,
pub num_songs: u32,
}

impl From<index::ArtistHeader> for ArtistHeader {
Expand All @@ -336,14 +337,14 @@ impl From<index::ArtistHeader> 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<AlbumHeader>,
pub albums_as_additional_performer: Vec<AlbumHeader>,
pub albums_as_composer: Vec<AlbumHeader>,
Expand All @@ -354,7 +355,7 @@ impl From<index::Artist> for Artist {
fn from(a: index::Artist) -> Self {
let convert_albums = |a: Vec<index::Album>| 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),
Expand Down

0 comments on commit e0bf259

Please sign in to comment.