diff --git a/server/ctrlsubsonic/handlers_by_tags.go b/server/ctrlsubsonic/handlers_by_tags.go index 9f0c5efb..4de4fb5d 100644 --- a/server/ctrlsubsonic/handlers_by_tags.go +++ b/server/ctrlsubsonic/handlers_by_tags.go @@ -185,13 +185,14 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response { // search "artists" var artists []*db.Artist q := c.DB. + Select("*, count(albums.id) album_count"). + Group("artists.id"). Where("name LIKE ? OR name_u_dec LIKE ?", query, query). + Joins("JOIN albums ON albums.tag_artist_id=artists.id"). Offset(params.GetOrInt("artistOffset", 0)). Limit(params.GetOrInt("artistCount", 20)) if m := c.getMusicFolder(params); m != "" { - q = q. - Joins("JOIN albums ON albums.tag_artist_id=artists.id"). - Where("albums.root_dir=?", m) + q = q.Where("albums.root_dir=?", m) } if err := q.Find(&artists).Error; err != nil { return spec.NewError(0, "find artists: %v", err) diff --git a/server/ctrlsubsonic/testdata/test_search_three_q_art b/server/ctrlsubsonic/testdata/test_search_three_q_art index d7446754..ab266d8f 100644 --- a/server/ctrlsubsonic/testdata/test_search_three_q_art +++ b/server/ctrlsubsonic/testdata/test_search_three_q_art @@ -5,9 +5,9 @@ "type": "gonic", "searchResult3": { "artist": [ - { "id": "ar-1", "name": "artist-0", "albumCount": 0 }, - { "id": "ar-2", "name": "artist-1", "albumCount": 0 }, - { "id": "ar-3", "name": "artist-2", "albumCount": 0 } + { "id": "ar-1", "name": "artist-0", "albumCount": 3 }, + { "id": "ar-2", "name": "artist-1", "albumCount": 3 }, + { "id": "ar-3", "name": "artist-2", "albumCount": 3 } ] } }