refactor: 提取 service 层 best-effort 超时常量
- 新增 defaultBETimeout = 5 * time.Second - 替换 auth/auth_runtime/password_reset/user_service/webhook 中 6 处硬编码 5*time.Second
This commit is contained in:
@@ -30,6 +30,7 @@ const (
|
||||
defaultTOTPChallengeTTL = 5 * time.Minute
|
||||
defaultPasswordMinLen = 8
|
||||
refreshTokenRetryGrace = 10 * time.Second
|
||||
defaultBETimeout = 5 * time.Second // best-effort 后台操作默认超时
|
||||
MaxUsernameAttempts = 100 // 最大尝试次数(P1性能优化:减少循环查询)
|
||||
MaxUsernameLength = 40 // 用户名最大长度
|
||||
)
|
||||
@@ -553,7 +554,7 @@ func (s *AuthService) writeLoginLog(
|
||||
log.Printf("auth: write login log panic recovered, user_id=%v login_type=%d err=%v", userID, loginType, r)
|
||||
}
|
||||
}()
|
||||
bgCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
bgCtx, cancel := context.WithTimeout(context.Background(), defaultBETimeout)
|
||||
defer cancel()
|
||||
if err := s.loginLogRepo.Create(bgCtx, loginRecord); err != nil {
|
||||
log.Printf("auth: write login log failed, user_id=%v login_type=%d err=%v", userID, loginType, err)
|
||||
@@ -634,7 +635,7 @@ func (s *AuthService) bestEffortRegisterDevice(ctx context.Context, userID int64
|
||||
log.Printf("auth: register device panic recovered, user_id=%d device_id=%s err=%v", userID, req.DeviceID, r)
|
||||
}
|
||||
}()
|
||||
bgCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
bgCtx, cancel := context.WithTimeout(context.Background(), defaultBETimeout)
|
||||
defer cancel()
|
||||
_, _ = s.deviceService.CreateDevice(bgCtx, userID, createReq)
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user