From 8aa0753b12bb954aeb8d4e75cf08bd4454b666f9 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 2 Sep 2026 17:40:43 +0800 Subject: [PATCH] fix(logs): flush small access-log batches within two seconds Default MinBatchSize of 50 left quiet admin traffic in memory forever because MaxFlushWait was unset. Force a timed flush so the logs page can show recent authenticated requests. --- backend/plugins/domain/risk_control/service.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/plugins/domain/risk_control/service.go b/backend/plugins/domain/risk_control/service.go index d25c84fd..c502027d 100644 --- a/backend/plugins/domain/risk_control/service.go +++ b/backend/plugins/domain/risk_control/service.go @@ -13,8 +13,12 @@ import ( "time" ) -// fallbackLogEngine 是日志库状态不可得时对外暴露的引擎标识。 -const fallbackLogEngine = "sqlite" +const ( + // fallbackLogEngine 是日志库状态不可得时对外暴露的引擎标识。 + fallbackLogEngine = "sqlite" + // accessLogMaxFlushWait 强制把不足 MinBatchSize 的访问日志刷盘,避免管理台低频访问永远看不到记录。 + accessLogMaxFlushWait = 2 * time.Second +) var ( logWriterMu sync.RWMutex @@ -30,6 +34,7 @@ func InitLogWriter(ctx context.Context) { } cfg := batchwriter.DefaultConfig() + cfg.MaxFlushWait = accessLogMaxFlushWait writer, err := batchwriter.New[*logstore.UserAccessLog](cfg, writeAccessLogBatch, batchwriter.WithDropHandler[*logstore.UserAccessLog](func(item *logstore.UserAccessLog) { path := ""