🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
request throttling only for media group api
Dimitri Herzogf1e1d3bc070e
diff --git a/server/server.go b/server/server.goindex 990caad73..6b7e5f9c1 100644--- a/server/server.go+++ b/server/server.go@@ -5,7 +5,6 @@ import ("os""path""path/filepath"- "runtime""time""github.com/deluan/navidrome/conf"@@ -13,7 +12,6 @@ import ("github.com/deluan/navidrome/log""github.com/deluan/navidrome/model""github.com/deluan/navidrome/scanner"- "github.com/deluan/navidrome/utils""github.com/go-chi/chi""github.com/go-chi/chi/middleware""github.com/go-chi/cors"@@ -64,10 +62,6 @@ func (a *Server) initRoutes() {r.Use(middleware.Heartbeat("/ping"))r.Use(InjectLogger)- // configure request throttling- maxRequests := utils.MaxInt(2, runtime.NumCPU())- r.Use(middleware.ThrottleBacklog(maxRequests, consts.RequestThrottleBacklogLimit, consts.RequestThrottleBacklogTimeout))-indexHtml := path.Join(conf.Server.BaseURL, consts.URLPathUI, "index.html")r.Get("/*", func(w http.ResponseWriter, r *http.Request) {http.Redirect(w, r, indexHtml, 302)diff --git a/server/subsonic/api.go b/server/subsonic/api.goindex 6feb26cfc..9717fab0d 100644--- a/server/subsonic/api.go+++ b/server/subsonic/api.go@@ -4,7 +4,11 @@ import ("encoding/json""encoding/xml""fmt"+ "github.com/deluan/navidrome/consts"+ "github.com/go-chi/chi/middleware"+ "math""net/http"+ "runtime""github.com/deluan/navidrome/engine""github.com/deluan/navidrome/log"@@ -116,8 +120,11 @@ func (api *Router) routes() http.Handler {})r.Group(func(r chi.Router) {c := initMediaRetrievalController(api)- H(r, "getAvatar", c.GetAvatar)- H(r, "getCoverArt", c.GetCoverArt)+ // configure request throttling+ maxRequests := math.Max(2, float64(runtime.NumCPU()))+ withThrottle := r.With(middleware.ThrottleBacklog(int(maxRequests), consts.RequestThrottleBacklogLimit, consts.RequestThrottleBacklogTimeout))+ H(withThrottle, "getAvatar", c.GetAvatar)+ H(withThrottle, "getCoverArt", c.GetCoverArt)})r.Group(func(r chi.Router) {c := initStreamController(api)