accounts: invalidate web user cache on changes as well
previously used app.jf.CacheExpiry = time.Now(), now either call app.InvalidateJellyfinCache() (when we only need it to get a user), or app.InvalidateUserCaches() (when the web user list needs to be updated).
This commit is contained in:
+1
-1
@@ -110,7 +110,7 @@ func (app *appContext) SetDefaultProfile(gc *gin.Context) {
|
|||||||
func (app *appContext) CreateProfile(gc *gin.Context) {
|
func (app *appContext) CreateProfile(gc *gin.Context) {
|
||||||
var req newProfileDTO
|
var req newProfileDTO
|
||||||
gc.BindJSON(&req)
|
gc.BindJSON(&req)
|
||||||
app.jf.CacheExpiry = time.Now()
|
app.InvalidateJellyfinCache()
|
||||||
user, err := app.jf.UserByID(req.ID, false)
|
user, err := app.jf.UserByID(req.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.err.Printf(lm.FailedGetUsers, lm.Jellyfin, err)
|
app.err.Printf(lm.FailedGetUsers, lm.Jellyfin, err)
|
||||||
|
|||||||
+3
-3
@@ -427,7 +427,7 @@ func (app *appContext) EnableDisableUsers(gc *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.jf.CacheExpiry = time.Now()
|
app.InvalidateUserCaches()
|
||||||
if len(errors["GetUser"]) != 0 || len(errors["SetPolicy"]) != 0 {
|
if len(errors["GetUser"]) != 0 || len(errors["SetPolicy"]) != 0 {
|
||||||
gc.JSON(500, errors)
|
gc.JSON(500, errors)
|
||||||
return
|
return
|
||||||
@@ -495,7 +495,7 @@ func (app *appContext) DeleteUsers(gc *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.jf.CacheExpiry = time.Now()
|
app.InvalidateUserCaches()
|
||||||
if len(errors) == len(req.Users) {
|
if len(errors) == len(req.Users) {
|
||||||
respondBool(500, false, gc)
|
respondBool(500, false, gc)
|
||||||
app.err.Printf(lm.FailedDeleteUsers, lm.Jellyfin, errors[req.Users[0]])
|
app.err.Printf(lm.FailedDeleteUsers, lm.Jellyfin, errors[req.Users[0]])
|
||||||
@@ -1179,7 +1179,7 @@ func (app *appContext) ApplySettings(gc *gin.Context) {
|
|||||||
|
|
||||||
} else if req.From == "user" {
|
} else if req.From == "user" {
|
||||||
applyingFromType = lm.User
|
applyingFromType = lm.User
|
||||||
app.jf.CacheExpiry = time.Now()
|
app.InvalidateJellyfinCache()
|
||||||
user, err := app.jf.UserByID(req.ID, false)
|
user, err := app.jf.UserByID(req.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.err.Printf(lm.FailedGetUser, req.ID, lm.Jellyfin, err)
|
app.err.Printf(lm.FailedGetUser, req.ID, lm.Jellyfin, err)
|
||||||
|
|||||||
+1
-1
@@ -140,7 +140,7 @@ func newHousekeepingDaemon(interval time.Duration, app *appContext) *GenericDaem
|
|||||||
clearPWR := app.config.Section("captcha").Key("enabled").MustBool(false) && !app.config.Section("captcha").Key("recaptcha").MustBool(false)
|
clearPWR := app.config.Section("captcha").Key("enabled").MustBool(false) && !app.config.Section("captcha").Key("recaptcha").MustBool(false)
|
||||||
|
|
||||||
if clearEmail || clearDiscord || clearTelegram || clearMatrix {
|
if clearEmail || clearDiscord || clearTelegram || clearMatrix {
|
||||||
d.appendJobs(func(app *appContext) { app.jf.CacheExpiry = time.Now() })
|
d.appendJobs(func(app *appContext) { app.InvalidateJellyfinCache() })
|
||||||
}
|
}
|
||||||
|
|
||||||
if clearEmail {
|
if clearEmail {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func (app *appContext) checkUsers() {
|
|||||||
expiry.DeleteAfterPeriod = true
|
expiry.DeleteAfterPeriod = true
|
||||||
app.storage.SetUserExpiryKey(user.ID, expiry)
|
app.storage.SetUserExpiryKey(user.ID, expiry)
|
||||||
}
|
}
|
||||||
app.jf.CacheExpiry = time.Now()
|
app.InvalidateJellyfinCache()
|
||||||
if contact {
|
if contact {
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
|
|||||||
+13
-2
@@ -10,13 +10,24 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FIXME: Invalidate cache on delete/modify/etc.
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
USER_DEFAULT_SORT_FIELD = "name"
|
USER_DEFAULT_SORT_FIELD = "name"
|
||||||
USER_DEFAULT_SORT_ASCENDING = true
|
USER_DEFAULT_SORT_ASCENDING = true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (app *appContext) InvalidateUserCaches() {
|
||||||
|
app.InvalidateJellyfinCache()
|
||||||
|
app.InvalidateWebUserCache()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *appContext) InvalidateJellyfinCache() {
|
||||||
|
app.jf.CacheExpiry = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *appContext) InvalidateWebUserCache() {
|
||||||
|
app.userCache.LastSync = time.Time{}
|
||||||
|
}
|
||||||
|
|
||||||
// UserCache caches the transport representation of users,
|
// UserCache caches the transport representation of users,
|
||||||
// complementing the built-in cache of the mediabrowser package.
|
// complementing the built-in cache of the mediabrowser package.
|
||||||
// Synchronisation runs in the background and consumers receive
|
// Synchronisation runs in the background and consumers receive
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ func (app *appContext) NewUserPostVerification(p NewUserParams) (out NewUserData
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
out.Created = true
|
out.Created = true
|
||||||
// Invalidate Cache to be safe
|
// Invalidate cache to be safe
|
||||||
app.jf.CacheExpiry = time.Now()
|
app.InvalidateUserCaches()
|
||||||
|
|
||||||
app.storage.SetActivityKey(shortuuid.New(), Activity{
|
app.storage.SetActivityKey(shortuuid.New(), Activity{
|
||||||
Type: ActivityCreation,
|
Type: ActivityCreation,
|
||||||
|
|||||||
Reference in New Issue
Block a user