mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
Return genres in search3 endpoint.
This commit is contained in:
parent
bb7186ce2f
commit
f69c27d146
3 changed files with 12 additions and 4 deletions
|
@ -154,6 +154,10 @@ func (r *albumRepository) purgeEmpty() error {
|
||||||
func (r *albumRepository) Search(q string, offset int, size int) (model.Albums, error) {
|
func (r *albumRepository) Search(q string, offset int, size int) (model.Albums, error) {
|
||||||
results := model.Albums{}
|
results := model.Albums{}
|
||||||
err := r.doSearch(q, offset, size, &results, "name")
|
err := r.doSearch(q, offset, size, &results, "name")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = r.loadAlbumGenres(&results)
|
||||||
return results, err
|
return results, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,10 @@ func (r *mediaFileRepository) removeNonAlbumArtistIds() error {
|
||||||
func (r *mediaFileRepository) Search(q string, offset int, size int) (model.MediaFiles, error) {
|
func (r *mediaFileRepository) Search(q string, offset int, size int) (model.MediaFiles, error) {
|
||||||
results := model.MediaFiles{}
|
results := model.MediaFiles{}
|
||||||
err := r.doSearch(q, offset, size, &results, "title")
|
err := r.doSearch(q, offset, size, &results, "title")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = r.loadMediaFileGenres(&results)
|
||||||
return results, err
|
return results, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (api *Router) getParams(r *http.Request) (*searchParams, error) {
|
||||||
|
|
||||||
type searchFunc[T any] func(q string, offset int, size int) (T, error)
|
type searchFunc[T any] func(q string, offset int, size int) (T, error)
|
||||||
|
|
||||||
func doSearch[T any](ctx context.Context, wg *sync.WaitGroup, s searchFunc[T], q string, offset, size int, result *T) {
|
func callSearch[T any](ctx context.Context, wg *sync.WaitGroup, s searchFunc[T], q string, offset, size int, result *T) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
return
|
return
|
||||||
|
@ -74,9 +74,9 @@ func (api *Router) searchAll(ctx context.Context, sp *searchParams) (mediaFiles
|
||||||
q := sanitize.Accents(strings.ToLower(strings.TrimSuffix(sp.query, "*")))
|
q := sanitize.Accents(strings.ToLower(strings.TrimSuffix(sp.query, "*")))
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(3)
|
wg.Add(3)
|
||||||
go doSearch(ctx, wg, api.ds.MediaFile(ctx).Search, q, sp.songOffset, sp.songCount, &mediaFiles)
|
go callSearch(ctx, wg, api.ds.MediaFile(ctx).Search, q, sp.songOffset, sp.songCount, &mediaFiles)
|
||||||
go doSearch(ctx, wg, api.ds.Album(ctx).Search, q, sp.albumOffset, sp.albumCount, &albums)
|
go callSearch(ctx, wg, api.ds.Album(ctx).Search, q, sp.albumOffset, sp.albumCount, &albums)
|
||||||
go doSearch(ctx, wg, api.ds.Artist(ctx).Search, q, sp.artistOffset, sp.artistCount, &artists)
|
go callSearch(ctx, wg, api.ds.Artist(ctx).Search, q, sp.artistOffset, sp.artistCount, &artists)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
if ctx.Err() == nil {
|
if ctx.Err() == nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue