Skip to content

🎧 Your Personal Streaming Service

Add dev option to increase external metadata cache expiration. More logs

Deluanad2ad514b32f
diff --git a/conf/configuration.go b/conf/configuration.go
index 55f87f00d..ee41432c0 100644
--- a/conf/configuration.go
+++ b/conf/configuration.go
@@ -86,6 +86,8 @@ type configOptions struct {
DevArtworkMaxRequests int
DevArtworkThrottleBacklogLimit int
DevArtworkThrottleBacklogTimeout time.Duration
+ DevArtistInfoTimeToLive time.Duration
+ DevAlbumInfoTimeToLive time.Duration
}
type scannerOptions struct {
@@ -291,6 +293,8 @@ func init() {
viper.SetDefault("devartworkmaxrequests", number.Max(2, runtime.NumCPU()/3))
viper.SetDefault("devartworkthrottlebackloglimit", consts.RequestThrottleBacklogLimit)
viper.SetDefault("devartworkthrottlebacklogtimeout", consts.RequestThrottleBacklogTimeout)
+ viper.SetDefault("devartistinfotimetolive", consts.ArtistInfoTimeToLive)
+ viper.SetDefault("devalbuminfotimetolive", consts.AlbumInfoTimeToLive)
}
func InitConfig(cfgFile string) {
diff --git a/core/external_metadata.go b/core/external_metadata.go
index 745891c67..85bb0cf8c 100644
--- a/core/external_metadata.go
+++ b/core/external_metadata.go
@@ -11,7 +11,7 @@ import (
"github.com/Masterminds/squirrel"
"github.com/deluan/sanitize"
- "github.com/navidrome/navidrome/consts"
+ "github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/core/agents"
_ "github.com/navidrome/navidrome/core/agents/lastfm"
_ "github.com/navidrome/navidrome/core/agents/listenbrainz"
@@ -90,7 +90,7 @@ func (e *externalMetadata) UpdateAlbumInfo(ctx context.Context, id string) (*mod
}
}
- if time.Since(album.ExternalInfoUpdatedAt) > consts.AlbumInfoTimeToLive {
+ if time.Since(album.ExternalInfoUpdatedAt) > conf.Server.DevAlbumInfoTimeToLive {
log.Debug("Found expired cached AlbumInfo, refreshing in the background", "updatedAt", album.ExternalInfoUpdatedAt, "name", album.Name)
go func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
@@ -205,7 +205,7 @@ func (e *externalMetadata) refreshArtistInfo(ctx context.Context, id string) (*a
}
// If info is expired, trigger a populateArtistInfo in the background
- if time.Since(artist.ExternalInfoUpdatedAt) > consts.ArtistInfoTimeToLive {
+ if time.Since(artist.ExternalInfoUpdatedAt) > conf.Server.DevArtistInfoTimeToLive {
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)
@@ -474,7 +474,9 @@ func (e *externalMetadata) callGetSimilar(ctx context.Context, agent agents.Arti
if len(similar) == 0 || err != nil {
return
}
+ start := time.Now()
sa, err := e.mapSimilarArtists(ctx, similar, includeNotPresent)
+ log.Debug(ctx, "Mapped Similar Artists", "agent", "artist", artist.Name, "numSimilar", len(sa), "elapsed", time.Since(start))
if err != nil {
return
}
diff --git a/server/public/public_endpoints.go b/server/public/public_endpoints.go
index 93538ca06..570cb1eb6 100644
--- a/server/public/public_endpoints.go
+++ b/server/public/public_endpoints.go
@@ -10,6 +10,7 @@ import (
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/core"
"github.com/navidrome/navidrome/core/artwork"
+ "github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/server"
"github.com/navidrome/navidrome/ui"
@@ -40,8 +41,10 @@ func (p *Router) routes() http.Handler {
r.Use(server.URLParamsMiddleware)
r.Group(func(r chi.Router) {
if conf.Server.DevArtworkMaxRequests > 0 {
- maxRequests := conf.Server.DevArtworkMaxRequests
- r.Use(middleware.ThrottleBacklog(maxRequests, conf.Server.DevArtworkThrottleBacklogLimit,
+ log.Debug("Public images endpoint will be throttled", "maxRequests", conf.Server.DevArtworkMaxRequests,
+ "backlogLimit", conf.Server.DevArtworkThrottleBacklogLimit, "backlogTimeout",
+ conf.Server.DevArtworkThrottleBacklogTimeout)
+ r.Use(middleware.ThrottleBacklog(conf.Server.DevArtworkMaxRequests, conf.Server.DevArtworkThrottleBacklogLimit,
conf.Server.DevArtworkThrottleBacklogTimeout))
}
r.HandleFunc("/img/{id}", p.handleImages)
diff --git a/server/subsonic/api.go b/server/subsonic/api.go
index 400ec260e..3f34bb81d 100644
--- a/server/subsonic/api.go
+++ b/server/subsonic/api.go
@@ -146,8 +146,10 @@ func (api *Router) routes() http.Handler {
r.Group(func(r chi.Router) {
// configure request throttling
if conf.Server.DevArtworkMaxRequests > 0 {
- maxRequests := conf.Server.DevArtworkMaxRequests
- r.Use(middleware.ThrottleBacklog(maxRequests, conf.Server.DevArtworkThrottleBacklogLimit,
+ log.Debug("Subsonic getCoverArt endpoint will be throttled", "maxRequests", conf.Server.DevArtworkMaxRequests,
+ "backlogLimit", conf.Server.DevArtworkThrottleBacklogLimit, "backlogTimeout",
+ conf.Server.DevArtworkThrottleBacklogTimeout)
+ r.Use(middleware.ThrottleBacklog(conf.Server.DevArtworkMaxRequests, conf.Server.DevArtworkThrottleBacklogLimit,
conf.Server.DevArtworkThrottleBacklogTimeout))
}
hr(r, "getCoverArt", api.GetCoverArt)