request throttling only for media group api
This commit is contained in:
committed by
Deluan Quintão
parent
694be54428
commit
f1e1d3bc07
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user