Skip to content

Commit

Permalink
Return genres in search3 endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
caiocotts authored and deluan committed Nov 22, 2023
1 parent bb7186c commit f69c27d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions persistence/album_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions persistence/mediafile_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions server/subsonic/searching.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f69c27d

Please sign in to comment.