diff --git a/src/open_subsonic/browsing/get_artists.rs b/src/open_subsonic/browsing/get_artists.rs index e1f4f3194..6f157fb1c 100644 --- a/src/open_subsonic/browsing/get_artists.rs +++ b/src/open_subsonic/browsing/get_artists.rs @@ -19,11 +19,11 @@ async fn get_indexed_artists( pool: &DatabasePool, user_id: Uuid, music_folder_ids: &Option>, -) -> Result> { +) -> Result> { #[add_permission_filter] get_basic_artist_id3_db() - .select((artists::index, BasicArtistId3Db::as_select())) - .get_results::<(String, BasicArtistId3Db)>(&mut pool.get().await?) + .select((artists::index, ArtistId3Db::as_select())) + .get_results::<(String, ArtistId3Db)>(&mut pool.get().await?) .await .map_err(anyhow::Error::from) } @@ -47,10 +47,7 @@ pub async fn get_artists( .into_iter() .into_group_map() .into_iter() - .map(|(k, v)| Index { - name: k, - artists: v.into_iter().map(BasicArtistId3Db::into).collect(), - }) + .map(|(k, v)| Index { name: k, artists: v.into_iter().map(ArtistId3Db::into).collect() }) .collect_vec(); Ok(Indexes { ignored_articles, index }) @@ -87,7 +84,7 @@ mod tests { .await .unwrap() .into_iter() - .map(|(_, artist)| artist.id) + .map(|(_, artist)| artist.basic.id) .sorted() .collect_vec(); assert_eq!(artist_ids, infra.artist_ids(&infra.artist_no_ids(..)).await); @@ -114,7 +111,7 @@ mod tests { .await .unwrap() .into_iter() - .map(|(_, artist)| artist.id) + .map(|(_, artist)| artist.basic.id) .sorted() .collect_vec(); assert!(artist_ids.contains(&artist_id)); @@ -141,7 +138,7 @@ mod tests { .await .unwrap() .into_iter() - .map(|(_, artist)| artist.id) + .map(|(_, artist)| artist.basic.id) .sorted() .collect_vec(); assert!(artist_ids.contains(&artist_id)); @@ -169,7 +166,7 @@ mod tests { .await .unwrap() .into_iter() - .map(|(_, artist)| artist.id) + .map(|(_, artist)| artist.basic.id) .sorted() .collect_vec(); assert!(artist_ids.contains(&artist_id)); @@ -205,7 +202,7 @@ mod tests { .await .unwrap() .into_iter() - .map(|(_, artist)| artist.id) + .map(|(_, artist)| artist.basic.id) .sorted() .collect_vec(); assert!(!artist_ids.contains(&artist_id)); diff --git a/src/open_subsonic/common/id3/db.rs b/src/open_subsonic/common/id3/db.rs index 5d55987af..72b4912d9 100644 --- a/src/open_subsonic/common/id3/db.rs +++ b/src/open_subsonic/common/id3/db.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use anyhow::Result; -use diesel::dsl::{count_distinct, sql, sum, AssumeNotNull}; +use diesel::dsl::{count_distinct, max, sql, sum, AssumeNotNull}; use diesel::expression::SqlLiteral; use diesel::{ helper_types, sql_types, ExpressionMethods, NullableExpressionMethods, QueryDsl, Queryable, @@ -94,6 +94,9 @@ pub struct BasicSongId3Db { pub struct SongId3Db { #[diesel(embed)] pub basic: BasicSongId3Db, + #[diesel(select_expression = max(albums::name).assume_not_null())] + #[diesel(select_expression_type = AssumeNotNull>)] + pub album: String, #[diesel(select_expression = sql("array_agg(distinct(songs_artists.artist_id)) artist_ids"))] #[diesel(select_expression_type = SqlLiteral::>)] pub artist_ids: Vec, @@ -244,6 +247,7 @@ impl SongId3Db { .basic .cover_art_id .map(|v| MediaTypedId { t: Some(MediaType::Song), id: v }), + album: Some(self.album), content_type: Some( mime_guess::from_ext(&self.basic.format) .first_or_octet_stream() diff --git a/src/open_subsonic/common/id3/query.rs b/src/open_subsonic/common/id3/query.rs index 76fee071a..bfcc84ce3 100644 --- a/src/open_subsonic/common/id3/query.rs +++ b/src/open_subsonic/common/id3/query.rs @@ -33,7 +33,10 @@ pub type GetBasicSongId3Db = Select, GetBasicGenreId3Db>, + LeftJoin< + InnerJoin, albums::table>, + GetBasicGenreId3Db, + >, songs::id, >, AsSelect, @@ -82,6 +85,7 @@ pub fn get_basic_song_id3_db() -> GetBasicSongId3Db { pub fn get_song_id3_db() -> GetSongId3Db { get_basic_song_id3_db() .inner_join(songs_artists::table) + .inner_join(albums::table) .left_join(get_basic_genre_id3_db()) .group_by(songs::id) .select(SongId3Db::as_select()) diff --git a/src/open_subsonic/searching/search3.rs b/src/open_subsonic/searching/search3.rs index 3363bda8f..22530caf3 100644 --- a/src/open_subsonic/searching/search3.rs +++ b/src/open_subsonic/searching/search3.rs @@ -52,9 +52,9 @@ async fn sync( ) -> Result { let artists = #[add_permission_filter] #[add_count_offset(artist)] - get_basic_artist_id3_db() + get_artist_id3_db() .order(artists::name.asc()) - .get_results::(&mut pool.get().await?) + .get_results::(&mut pool.get().await?) .await?; let albums = #[add_permission_filter] @@ -72,7 +72,7 @@ async fn sync( .await?; Ok(Search3Result { - artists: artists.into_iter().map(BasicArtistId3Db::into).collect(), + artists: artists.into_iter().map(ArtistId3Db::into).collect(), albums: stream::iter(albums) .then(|v| async move { v.into(pool).await }) .try_collect() @@ -100,7 +100,7 @@ async fn full_text_search( ) -> Result { let artists = #[add_permission_filter] #[add_count_offset(artist)] - get_basic_artist_id3_db() + get_artist_id3_db() .filter( artists::ts .matches(websearch_to_tsquery_with_search_config(USIMPLE_TS_CONFIGURATION, &query)), @@ -112,7 +112,7 @@ async fn full_text_search( ) .desc(), ) - .get_results::(&mut pool.get().await?) + .get_results::(&mut pool.get().await?) .await?; let albums = #[add_permission_filter] @@ -134,7 +134,7 @@ async fn full_text_search( let songs = #[add_permission_filter] #[add_count_offset(song)] - get_basic_song_id3_db() + get_song_id3_db() .filter( songs::ts .matches(websearch_to_tsquery_with_search_config(USIMPLE_TS_CONFIGURATION, &query)), @@ -146,13 +146,16 @@ async fn full_text_search( ) .desc(), ) - .get_results::(&mut pool.get().await?) + .get_results::(&mut pool.get().await?) .await?; Ok(Search3Result { - artists: artists.into_iter().map(BasicArtistId3Db::into).collect(), + artists: artists.into_iter().map(ArtistId3Db::into).collect(), albums: albums.into_iter().map(BasicAlbumId3Db::into).collect(), - songs: songs.into_iter().map(BasicSongId3Db::into).collect(), + songs: stream::iter(songs) + .then(|v| async move { v.into(pool).await }) + .try_collect() + .await?, }) } diff --git a/types/src/common/id3/response.rs b/types/src/common/id3/response.rs index 510572726..581ca907d 100644 --- a/types/src/common/id3/response.rs +++ b/types/src/common/id3/response.rs @@ -92,6 +92,9 @@ pub struct SongId3 { pub cover_art: Option, #[new(default)] #[serde(skip_serializing_if = "Option::is_none", default)] + pub album: Option, + #[new(default)] + #[serde(skip_serializing_if = "Option::is_none", default)] pub content_type: Option, #[new(default)] #[serde(skip_serializing_if = "Vec::is_empty", default)]