🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Smarter cache of external info calls (last.fm / spotify)
Deluan68a84ec832c5
diff --git a/consts/consts.go b/consts/consts.goindex af7f74a6a..65797a623 100644--- a/consts/consts.go+++ b/consts/consts.go@@ -41,7 +41,7 @@ const (RequestThrottleBacklogLimit = 100RequestThrottleBacklogTimeout = time.Minute- ArtistInfoTimeToLive = 3 * 24 * time.Hour+ ArtistInfoTimeToLive = 24 * time.HourI18nFolder = "i18n"SkipScanFile = ".ndignore"diff --git a/core/external_metadata.go b/core/external_metadata.goindex f3569637e..2ea8d0237 100644--- a/core/external_metadata.go+++ b/core/external_metadata.go@@ -83,8 +83,18 @@ func (e *externalMetadata) UpdateArtistInfo(ctx context.Context, id string, simireturn nil, err}- // If we have fresh info, just return it and trigger a refresh in the background- if time.Since(artist.ExternalInfoUpdatedAt) < consts.ArtistInfoTimeToLive {+ // If we don't have any info, retrieves it now+ if artist.ExternalInfoUpdatedAt.IsZero() {+ log.Debug(ctx, "ArtistInfo not cached. Retrieving it now", "updatedAt", artist.ExternalInfoUpdatedAt, "id", id, "name", artist.Name)+ err = e.refreshArtistInfo(ctx, artist)+ if err != nil {+ return nil, err+ }+ }++ // If info is expired, trigger a refresh in the background+ if time.Since(artist.ExternalInfoUpdatedAt) > consts.ArtistInfoTimeToLive {+ log.Debug("Found expired cached ArtistInfo, refreshing in the background", "updatedAt", artist.ExternalInfoUpdatedAt, "name", artist.Name)go func() {ctx, cancel := context.WithTimeout(context.Background(), time.Minute)defer cancel()@@ -93,16 +103,8 @@ func (e *externalMetadata) UpdateArtistInfo(ctx context.Context, id string, similog.Error("Error refreshing ArtistInfo", "id", id, "name", artist.Name, err)}}()- log.Debug("Found cached ArtistInfo, refreshing in the background", "updatedAt", artist.ExternalInfoUpdatedAt, "name", artist.Name)- err := e.loadSimilar(ctx, artist, similarCount, includeNotPresent)- return &artist.Artist, err}- log.Debug(ctx, "ArtistInfo not cached or expired", "updatedAt", artist.ExternalInfoUpdatedAt, "id", id, "name", artist.Name)- err = e.refreshArtistInfo(ctx, artist)- if err != nil {- return nil, err- }err = e.loadSimilar(ctx, artist, similarCount, includeNotPresent)return &artist.Artist, err}