mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-10 23:36:37 +08:00
fix: 防止启动整理扫描阻塞登录
This commit is contained in:
@@ -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)
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user