Artist key cleanup

This commit is contained in:
Antoine Gersant 2024-09-29 12:14:36 -07:00
parent e06f79c500
commit ef6951faba
4 changed files with 21 additions and 28 deletions

View file

@ -173,7 +173,7 @@ impl Manager {
.strings
.get(name)
.ok_or_else(|| Error::ArtistNotFound)?;
let artist_key = ArtistKey { name };
let artist_key = ArtistKey(name);
index
.collection
.get_artist(&index.strings, artist_key)
@ -197,7 +197,7 @@ impl Manager {
artists: artists
.into_iter()
.filter_map(|a| index.strings.get(a))
.map(|k| ArtistKey { name: k })
.map(|k| ArtistKey(k))
.collect(),
name,
};

View file

@ -232,7 +232,7 @@ fn make_album_header(album: &storage::Album, strings: &RodeoReader) -> AlbumHead
artists: album
.artists
.iter()
.map(|a| strings.resolve(&a.name).to_string())
.map(|a| strings.resolve(&a.0).to_string())
.collect(),
year: album.year,
date_added: album.date_added,
@ -364,7 +364,7 @@ impl Builder {
self.artists
.entry(artist_key)
.or_insert_with(|| storage::Artist {
name: artist_key.name,
name: artist_key.0,
all_albums: HashSet::new(),
albums_as_performer: HashSet::new(),
albums_as_additional_performer: HashSet::new(),
@ -777,12 +777,8 @@ mod test {
},
]));
let artist = collection.get_artist(
&strings,
ArtistKey {
name: strings.get("Stratovarius").unwrap(),
},
);
let artist =
collection.get_artist(&strings, ArtistKey(strings.get("Stratovarius").unwrap()));
let names = artist
.unwrap()
@ -843,12 +839,11 @@ mod test {
},
]));
let artist = ArtistKey(strings.get("FSOL").unwrap());
let album = collection.get_album(
&strings,
AlbumKey {
artists: tiny_vec![ArtistKey {
name: strings.get("FSOL").unwrap()
}],
artists: tiny_vec!([ArtistKey; 4] => artist),
name: strings.get("Lifeforms").unwrap(),
},
);

View file

@ -287,11 +287,11 @@ impl Builder {
.iter()
.zip(storage_song.album_artists.iter())
{
self.text_fields[TextField::AlbumArtist].insert(str, artist_key.name, song_key);
self.text_fields[TextField::AlbumArtist].insert(str, artist_key.0, song_key);
}
for (str, artist_key) in scanner_song.artists.iter().zip(storage_song.artists.iter()) {
self.text_fields[TextField::Artist].insert(str, artist_key.name, song_key);
self.text_fields[TextField::Artist].insert(str, artist_key.0, song_key);
}
for (str, artist_key) in scanner_song
@ -299,7 +299,7 @@ impl Builder {
.iter()
.zip(storage_song.composers.iter())
{
self.text_fields[TextField::Composer].insert(str, artist_key.name, song_key);
self.text_fields[TextField::Composer].insert(str, artist_key.0, song_key);
}
if let Some(disc_number) = &scanner_song.disc_number {
@ -319,7 +319,7 @@ impl Builder {
.iter()
.zip(storage_song.lyricists.iter())
{
self.text_fields[TextField::Lyricist].insert(str, artist_key.name, song_key);
self.text_fields[TextField::Lyricist].insert(str, artist_key.0, song_key);
}
self.text_fields[TextField::Path].insert(

View file

@ -75,9 +75,7 @@ pub struct GenreKey {
}
#[derive(Copy, Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ArtistKey {
pub name: Spur,
}
pub struct ArtistKey(pub Spur);
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct AlbumKey {
@ -166,13 +164,13 @@ pub fn store_song(
.artists
.iter()
.filter_map(&mut canonicalize)
.map(|k| ArtistKey { name: k })
.map(|k| ArtistKey(k))
.collect(),
album_artists: song
.album_artists
.iter()
.filter_map(&mut canonicalize)
.map(|k| ArtistKey { name: k })
.map(|k| ArtistKey(k))
.collect(),
year: song.year,
album: song.album.as_ref().and_then(&mut canonicalize),
@ -182,13 +180,13 @@ pub fn store_song(
.lyricists
.iter()
.filter_map(&mut canonicalize)
.map(|k| ArtistKey { name: k })
.map(|k| ArtistKey(k))
.collect(),
composers: song
.composers
.iter()
.filter_map(&mut canonicalize)
.map(|k| ArtistKey { name: k })
.map(|k| ArtistKey(k))
.collect(),
genres: song.genres.iter().filter_map(&mut canonicalize).collect(),
labels: song.labels.iter().filter_map(&mut canonicalize).collect(),
@ -206,12 +204,12 @@ pub fn fetch_song(strings: &RodeoReader, song: &Song) -> super::Song {
artists: song
.artists
.iter()
.map(|k| strings.resolve(&k.name).to_string())
.map(|k| strings.resolve(&k.0).to_string())
.collect(),
album_artists: song
.album_artists
.iter()
.map(|k| strings.resolve(&k.name).to_string())
.map(|k| strings.resolve(&k.0).to_string())
.collect(),
year: song.year,
album: song.album.map(|s| strings.resolve(&s).to_string()),
@ -220,12 +218,12 @@ pub fn fetch_song(strings: &RodeoReader, song: &Song) -> super::Song {
lyricists: song
.lyricists
.iter()
.map(|k| strings.resolve(&k.name).to_string())
.map(|k| strings.resolve(&k.0).to_string())
.collect(),
composers: song
.composers
.iter()
.map(|k| strings.resolve(&k.name).to_string())
.map(|k| strings.resolve(&k.0).to_string())
.collect(),
genres: song
.genres