From 1da1c255f6c5888c8dfb85004160e6ee2d48ec79 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 2 Feb 2026 22:45:27 +0800 Subject: [PATCH] :art: Improve data indexing to reduce disk read operations https://github.com/siyuan-note/siyuan/issues/16958 Signed-off-by: Daniel <845765@qq.com> --- kernel/sql/queue_history.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/sql/queue_history.go b/kernel/sql/queue_history.go index 63a585d48..a9871fc63 100644 --- a/kernel/sql/queue_history.go +++ b/kernel/sql/queue_history.go @@ -20,7 +20,10 @@ import ( "database/sql" "errors" "fmt" + "os" + "path/filepath" "runtime/debug" + "strings" "sync" "time" @@ -83,6 +86,15 @@ func FlushHistoryQueue() { if err = execHistoryOp(op, tx, context); err != nil { tx.Rollback() logging.LogErrorf("queue operation failed: %s", err) + + if 0 < len(op.histories) { + dir := op.histories[0].Path[:strings.Index(op.histories[0].Path, "/")] + dirPath := filepath.Join(util.HistoryDir, dir) + if removeErr := os.RemoveAll(dirPath); nil != removeErr { + logging.LogErrorf("remove corrupted history dir [%s] failed: %s", dirPath, removeErr) + } + } + eventbus.Publish(util.EvtSQLHistoryRebuild) return }