mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-23 01:20:11 +00:00
Users: Add delay when modifying >100 users
Hopefully avoids Jellyfin crashing. For #160
This commit is contained in:
parent
36f3860c4c
commit
94e3c13b3e
14
api.go
14
api.go
@ -1715,11 +1715,22 @@ func (app *appContext) ApplySettings(gc *gin.Context) {
|
||||
"policy": map[string]string{},
|
||||
"homescreen": map[string]string{},
|
||||
}
|
||||
/* Jellyfin doesn't seem to like too many of these requests sent in succession
|
||||
and can crash and mess up its database. Issue #160 says this occurs when more
|
||||
than 100 users are modified. A delay totalling 500ms between requests is used
|
||||
if so. */
|
||||
var shouldDelay bool = len(req.ApplyTo) >= 100
|
||||
if shouldDelay {
|
||||
app.debug.Println("Adding delay between requests for large batch")
|
||||
}
|
||||
for _, id := range req.ApplyTo {
|
||||
status, err := app.jf.SetPolicy(id, policy)
|
||||
if !(status == 200 || status == 204) || err != nil {
|
||||
errors["policy"][id] = fmt.Sprintf("%d: %s", status, err)
|
||||
}
|
||||
if shouldDelay {
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
}
|
||||
if req.Homescreen {
|
||||
status, err = app.jf.SetConfiguration(id, configuration)
|
||||
errorString := ""
|
||||
@ -1735,6 +1746,9 @@ func (app *appContext) ApplySettings(gc *gin.Context) {
|
||||
errors["homescreen"][id] = errorString
|
||||
}
|
||||
}
|
||||
if shouldDelay {
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
code := 200
|
||||
if len(errors["policy"]) == len(req.ApplyTo) || len(errors["homescreen"]) == len(req.ApplyTo) {
|
||||
|
Loading…
Reference in New Issue
Block a user