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
View File
@@ -8,6 +8,7 @@ package service
import (
"context"
"time"
"go.uber.org/zap"
@@ -39,3 +40,16 @@ func (a *AuditService) Record(ctx context.Context, userID, action, target, ip, d
a.log.Debug("audit write failed", zap.Error(err))
}
}
// RecordBestEffort writes an audit row off the request path. Login must not be
// held open by SQLite write pressure from scans or background maintenance.
func (a *AuditService) RecordBestEffort(userID, action, target, ip, detail string) {
if a == nil || a.repo == nil || a.repo.Log == nil {
return
}
go func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
a.Record(ctx, userID, action, target, ip, detail)
}()
}