mirror of
https://github.com/hrfee/jfa-go.git
synced 2026-03-18 21:50:33 +01:00
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:
@@ -110,7 +110,7 @@ func (app *appContext) SetDefaultProfile(gc *gin.Context) {
|
||||
func (app *appContext) CreateProfile(gc *gin.Context) {
|
||||
var req newProfileDTO
|
||||
gc.BindJSON(&req)
|
||||
app.jf.CacheExpiry = time.Now()
|
||||
app.InvalidateJellyfinCache()
|
||||
user, err := app.jf.UserByID(req.ID, false)
|
||||
if err != nil {
|
||||
app.err.Printf(lm.FailedGetUsers, lm.Jellyfin, err)
|
||||
|
||||
@@ -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 {
|
||||
gc.JSON(500, errors)
|
||||
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) {
|
||||
respondBool(500, false, gc)
|
||||
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" {
|
||||
applyingFromType = lm.User
|
||||
app.jf.CacheExpiry = time.Now()
|
||||
app.InvalidateJellyfinCache()
|
||||
user, err := app.jf.UserByID(req.ID, false)
|
||||
if err != nil {
|
||||
app.err.Printf(lm.FailedGetUser, req.ID, lm.Jellyfin, err)
|
||||
|
||||
@@ -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)
|
||||
|
||||
if clearEmail || clearDiscord || clearTelegram || clearMatrix {
|
||||
d.appendJobs(func(app *appContext) { app.jf.CacheExpiry = time.Now() })
|
||||
d.appendJobs(func(app *appContext) { app.InvalidateJellyfinCache() })
|
||||
}
|
||||
|
||||
if clearEmail {
|
||||
|
||||
@@ -104,7 +104,7 @@ func (app *appContext) checkUsers() {
|
||||
expiry.DeleteAfterPeriod = true
|
||||
app.storage.SetUserExpiryKey(user.ID, expiry)
|
||||
}
|
||||
app.jf.CacheExpiry = time.Now()
|
||||
app.InvalidateJellyfinCache()
|
||||
if contact {
|
||||
if !ok {
|
||||
continue
|
||||
|
||||
15
usercache.go
15
usercache.go
@@ -10,13 +10,24 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// FIXME: Invalidate cache on delete/modify/etc.
|
||||
|
||||
const (
|
||||
USER_DEFAULT_SORT_FIELD = "name"
|
||||
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,
|
||||
// complementing the built-in cache of the mediabrowser package.
|
||||
// Synchronisation runs in the background and consumers receive
|
||||
|
||||
4
users.go
4
users.go
@@ -99,8 +99,8 @@ func (app *appContext) NewUserPostVerification(p NewUserParams) (out NewUserData
|
||||
return
|
||||
}
|
||||
out.Created = true
|
||||
// Invalidate Cache to be safe
|
||||
app.jf.CacheExpiry = time.Now()
|
||||
// Invalidate cache to be safe
|
||||
app.InvalidateUserCaches()
|
||||
|
||||
app.storage.SetActivityKey(shortuuid.New(), Activity{
|
||||
Type: ActivityCreation,
|
||||
|
||||
Reference in New Issue
Block a user