diff --git a/persistence/album_repository.go b/persistence/album_repository.go index 08e7e17aa..8f0fffc4a 100644 --- a/persistence/album_repository.go +++ b/persistence/album_repository.go @@ -154,6 +154,10 @@ func (r *albumRepository) purgeEmpty() error { func (r *albumRepository) Search(q string, offset int, size int) (model.Albums, error) { results := model.Albums{} err := r.doSearch(q, offset, size, &results, "name") + if err != nil { + return nil, err + } + err = r.loadAlbumGenres(&results) return results, err } diff --git a/persistence/mediafile_repository.go b/persistence/mediafile_repository.go index d487b6445..d242a2813 100644 --- a/persistence/mediafile_repository.go +++ b/persistence/mediafile_repository.go @@ -187,6 +187,10 @@ func (r *mediaFileRepository) removeNonAlbumArtistIds() error { func (r *mediaFileRepository) Search(q string, offset int, size int) (model.MediaFiles, error) { results := model.MediaFiles{} err := r.doSearch(q, offset, size, &results, "title") + if err != nil { + return nil, err + } + err = r.loadMediaFileGenres(&results) return results, err } diff --git a/server/subsonic/searching.go b/server/subsonic/searching.go index 3aafa3c53..8b3e276c7 100644 --- a/server/subsonic/searching.go +++ b/server/subsonic/searching.go @@ -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) -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() if size == 0 { return @@ -74,9 +74,9 @@ func (api *Router) searchAll(ctx context.Context, sp *searchParams) (mediaFiles q := sanitize.Accents(strings.ToLower(strings.TrimSuffix(sp.query, "*"))) wg := &sync.WaitGroup{} wg.Add(3) - go doSearch(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 doSearch(ctx, wg, api.ds.Artist(ctx).Search, q, sp.artistOffset, sp.artistCount, &artists) + go callSearch(ctx, wg, api.ds.MediaFile(ctx).Search, q, sp.songOffset, sp.songCount, &mediaFiles) + go callSearch(ctx, wg, api.ds.Album(ctx).Search, q, sp.albumOffset, sp.albumCount, &albums) + go callSearch(ctx, wg, api.ds.Artist(ctx).Search, q, sp.artistOffset, sp.artistCount, &artists) wg.Wait() if ctx.Err() == nil {