fix: allow login during sqlite write pressure

This commit is contained in:
ShukeBta
2026-06-11 20:06:55 +08:00
parent 7274ea19b7
commit 52d75171b2
10 changed files with 225 additions and 16 deletions
+22 -2
View File
@@ -19,7 +19,15 @@ func activeUserRequired(svc *service.Container) gin.HandlerFunc {
return
}
u, err := svc.Repo.User.FindByID(c.Request.Context(), userID)
if err != nil || u == nil {
if err != nil {
if service.IsTransientDatabaseLock(err) {
c.Next()
return
}
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"code": 40101, "message": "user not found"})
return
}
if u == nil {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"code": 40101, "message": "user not found"})
return
}
@@ -40,7 +48,19 @@ func activeEmbyUserRequired(svc *service.Container) gin.HandlerFunc {
uid, _ := c.Get(middleware.CtxUserID)
userID, _ := uid.(string)
u, err := svc.Repo.User.FindByID(c.Request.Context(), userID)
if userID == "" || err != nil || u == nil {
if userID == "" {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"Code": 40101, "Message": "User not found"})
return
}
if err != nil {
if service.IsTransientDatabaseLock(err) {
c.Next()
return
}
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"Code": 40101, "Message": "User not found"})
return
}
if u == nil {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"Code": 40101, "Message": "User not found"})
return
}