Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browsing): get top songs for album artists #94

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading