mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-10 04:12:29 +03:00
Replace custom code with errgroup
This commit is contained in:
parent
797cc87141
commit
ee6b10db72
@ -6,7 +6,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
@ -20,6 +19,7 @@ import (
|
|||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
"github.com/navidrome/navidrome/utils"
|
"github.com/navidrome/navidrome/utils"
|
||||||
"github.com/navidrome/navidrome/utils/number"
|
"github.com/navidrome/navidrome/utils/number"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -229,12 +229,13 @@ func (e *externalMetadata) populateArtistInfo(ctx context.Context, artist *auxAr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call all registered agents and collect information
|
// Call all registered agents and collect information
|
||||||
callParallel([]func(){
|
g := errgroup.Group{}
|
||||||
func() { e.callGetBiography(ctx, e.ag, artist) },
|
g.SetLimit(2)
|
||||||
func() { e.callGetURL(ctx, e.ag, artist) },
|
g.Go(func() error { e.callGetImage(ctx, e.ag, artist); return nil })
|
||||||
func() { e.callGetImage(ctx, e.ag, artist) },
|
g.Go(func() error { e.callGetBiography(ctx, e.ag, artist); return nil })
|
||||||
func() { e.callGetSimilar(ctx, e.ag, artist, maxSimilarArtists, true) },
|
g.Go(func() error { e.callGetURL(ctx, e.ag, artist); return nil })
|
||||||
})
|
g.Go(func() error { e.callGetSimilar(ctx, e.ag, artist, maxSimilarArtists, true); return nil })
|
||||||
|
_ = g.Wait()
|
||||||
|
|
||||||
if utils.IsCtxDone(ctx) {
|
if utils.IsCtxDone(ctx) {
|
||||||
log.Warn(ctx, "ArtistInfo update canceled", "elapsed", "id", artist.ID, "name", artist.Name, time.Since(start), ctx.Err())
|
log.Warn(ctx, "ArtistInfo update canceled", "elapsed", "id", artist.ID, "name", artist.Name, time.Since(start), ctx.Err())
|
||||||
@ -252,18 +253,6 @@ func (e *externalMetadata) populateArtistInfo(ctx context.Context, artist *auxAr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func callParallel(fs []func()) {
|
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
wg.Add(len(fs))
|
|
||||||
for _, f := range fs {
|
|
||||||
go func(f func()) {
|
|
||||||
f()
|
|
||||||
wg.Done()
|
|
||||||
}(f)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *externalMetadata) SimilarSongs(ctx context.Context, id string, count int) (model.MediaFiles, error) {
|
func (e *externalMetadata) SimilarSongs(ctx context.Context, id string, count int) (model.MediaFiles, error) {
|
||||||
artist, err := e.getArtist(ctx, id)
|
artist, err := e.getArtist(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user