Skip to content

Commit

Permalink
fix(browsing): get top songs for album artists (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
vnghia authored Apr 14, 2024
1 parent 0af2378 commit 4b882c8
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/open_subsonic/browsing/get_top_songs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ async fn get_top_songs(
count: Option<u32>,
) -> Result<Vec<SongId3Db>> {
get_song_id3_db()
.left_join(songs_album_artists::table)
.inner_join(
artists::table
.on(artists::id.eq(songs_artists::artist_id).and(artists::name.eq(artist))),
artists::table.on(artists::name.eq(artist).and(
artists::id
.eq(songs_artists::artist_id)
.or(artists::id.eq(songs_album_artists::album_artist_id)),
)),
)
.left_join(playbacks::table)
.order(sum(playbacks::count).desc().nulls_last())
Expand Down Expand Up @@ -78,6 +82,23 @@ mod tests {
assert_eq!(top_songs.len(), n_song);
}

#[tokio::test]
async fn test_get_top_songs_album_artist_no_empty() {
let artist_name = "artist";
let n_song = 20_usize;
let mut infra = Infra::new().await.n_folder(1).await.add_user(None).await;
infra.add_songs(
0,
(0..n_song)
.map(|_| SongTag { album_artists: vec![artist_name.into()], ..Faker.fake() })
.collect(),
);
infra.add_n_song(0, 10).scan(.., None).await;

let top_songs = get_top_songs(infra.pool(), artist_name.into(), None).await.unwrap();
assert_eq!(top_songs.len(), n_song);
}

#[tokio::test]
async fn test_get_top_songs_distinct() {
let artist_name = "artist";
Expand Down

0 comments on commit 4b882c8

Please sign in to comment.