🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Fix race condition in external metadata retrieval
Deluan6d526870b7d0
diff --git a/core/external_metadata.go b/core/external_metadata.goindex a6ff066fa..4fab72dda 100644--- a/core/external_metadata.go+++ b/core/external_metadata.go@@ -43,8 +43,8 @@ type ExternalMetadata interface {type externalMetadata struct {ds model.DataStoreag *agents.Agents- artistQueue refreshQueue[*auxArtist]- albumQueue refreshQueue[*auxAlbum]+ artistQueue refreshQueue[auxArtist]+ albumQueue refreshQueue[auxAlbum]}type auxAlbum struct {@@ -103,7 +103,7 @@ func (e *externalMetadata) UpdateAlbumInfo(ctx context.Context, id string) (*mod// If info is expired, trigger a populateAlbumInfo in the backgroundif time.Since(updatedAt) > conf.Server.DevAlbumInfoTimeToLive {log.Debug("Found expired cached AlbumInfo, refreshing in the background", "updatedAt", album.ExternalInfoUpdatedAt, "name", album.Name)- e.albumQueue.enqueue(album)+ e.albumQueue.enqueue(*album)}return &album.Album, nil@@ -206,7 +206,7 @@ func (e *externalMetadata) refreshArtistInfo(ctx context.Context, id string) (*a// If info is expired, trigger a populateArtistInfo in the backgroundif time.Since(updatedAt) > conf.Server.DevArtistInfoTimeToLive {log.Debug("Found expired cached ArtistInfo, refreshing in the background", "updatedAt", updatedAt, "name", artist.Name)- e.artistQueue.enqueue(artist)+ e.artistQueue.enqueue(*artist)}return artist, nil}@@ -554,15 +554,15 @@ func (e *externalMetadata) loadSimilar(ctx context.Context, artist *auxArtist, ctype refreshQueue[T any] chan<- T-func newRefreshQueue[T any](ctx context.Context, processFn func(context.Context, T) error) refreshQueue[T] {+func newRefreshQueue[T any](ctx context.Context, processFn func(context.Context, *T) error) refreshQueue[T] {queue := make(chan T, refreshQueueLength)go func() {for {time.Sleep(refreshDelay)ctx, cancel := context.WithTimeout(ctx, refreshTimeout)select {- case a := <-queue:- _ = processFn(ctx, a)+ case item := <-queue:+ _ = processFn(ctx, &item)cancel()case <-ctx.Done():cancel()