fix: 防止启动整理扫描阻塞登录

This commit is contained in:
ShukeBta
2026-06-12 19:06:47 +08:00
parent 1568ae127a
commit d270e9034f
11 changed files with 312 additions and 34 deletions
+14 -1
View File
@@ -163,10 +163,23 @@ func (s *AuthService) Login(ctx context.Context, username, password string) (*Lo
if err != nil {
return nil, err
}
_ = s.repo.User.TouchLogin(ctx, u.ID)
s.touchLoginBestEffort(u.ID)
return &LoginResponse{User: u, Tokens: tokens}, nil
}
func (s *AuthService) touchLoginBestEffort(userID string) {
if s == nil || s.repo == nil || s.repo.User == nil || strings.TrimSpace(userID) == "" {
return
}
go func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
if err := s.repo.User.TouchLogin(ctx, userID); err != nil && s.log != nil {
s.log.Debug("touch login delayed", zap.String("user_id", userID), zap.Error(err))
}
}()
}
// ChangePassword updates the user password if the old one matches.
func (s *AuthService) ChangePassword(ctx context.Context, userID, oldPwd, newPwd string) error {
if strings.TrimSpace(newPwd) == "" || len(newPwd) < 6 {