fix(server): don't update last access for internal plugin calls (#6501)

Plugin SubsonicAPI calls are served by the Subsonic router as the user, so UpdateLastAccessMiddleware marked every user a plugin reads for as active. These requests already carry request.WithInternalAuth; skip the update for them.

Fixes #6497

Signed-off-by: nenadjokic <nenad.jokic@me.com>
This commit is contained in:
Nenad 2026-11-18 14:40:43 +01:00 committed by GitHub
parent a40f7b870f
commit 2f85c631bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -374,7 +374,9 @@ func UpdateLastAccessMiddleware(ds model.DataStore) func(next http.Handler) http
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
usr, ok := request.UserFrom(ctx)
if ok {
// Internal calls (e.g. plugins) are not user activity: skip the last access update.
_, internal := request.InternalAuthFrom(ctx)
if ok && !internal {
userAccessLimiter.Do(usr.ID, func() {
start := time.Now()
ctx, cancel := context.WithTimeout(ctx, time.Second)

View File

@ -424,6 +424,28 @@ var _ = Describe("middlewares", func() {
req = req.WithContext(ctx)
callMiddleware(req)
usr, _ := ds.MockedUser.FindByUsername(ctx, "johndoe")
Expect(usr.LastAccessAt).To(Equal(&lastAccessTime))
})
})
Context("when the request is an internal call (e.g. from a plugin)", func() {
BeforeEach(func() {
req = req.WithContext(request.WithInternalAuth(req.Context(), "johndoe"))
})
It("calls the next handler", func() {
called := false
middleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
called = true
})).ServeHTTP(nil, req)
Expect(called).To(BeTrue())
})
It("does not update the last access time", func() {
time.Sleep(3 * time.Millisecond)
callMiddleware(req)
usr, _ := ds.MockedUser.FindByUsername(ctx, "johndoe")
Expect(usr.LastAccessAt).To(Equal(&lastAccessTime))
})