Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/17545#issuecomment-4293316202

Daniel1ae36f885eb3
diff --git a/kernel/sql/queue.go b/kernel/sql/queue.go
index b09f295374..c6b50f509d 100644
--- a/kernel/sql/queue.go
+++ b/kernel/sql/queue.go
@@ -20,6 +20,7 @@ import (
"database/sql"
"errors"
"fmt"
+ "math"
"path"
"runtime/debug"
"sync"
@@ -122,6 +123,30 @@ func FlushQueue() {
// logging.LogInfof("flushing database queue, total operations [%d]", total)
+ // 如果有重命名树的操作,则统计各路径前缀的块树数量,数量较大的话阻塞整个队列,以便尽可能合并重命名树的操作 RenameTreeQueue(tree)
+ var renameTreeOp *dbQueueOperation
+ for _, op := range ops {
+ if "rename" == op.action {
+ renameTreeOp = op
+ break
+ }
+ }
+ if nil != renameTreeOp {
+ childCount := treenode.CountBlockTreesByPathPrefix(path.Dir(renameTreeOp.indexTree.Path))
+ if 512 < childCount {
+ scale := math.Log(float64(childCount)/512.0+1.0) / math.Log(2.0)
+ secs := 1.0 * scale
+ if secs < 1.0 {
+ secs = 1.0
+ }
+ if secs > 12.0 {
+ secs = 12.0
+ }
+ logging.LogInfof("rename tree [%s] with large child count [%d], sleep [%.2fs] to wait for more operations", renameTreeOp.indexTree.Path, childCount, secs)
+ time.Sleep(time.Duration(secs * float64(time.Second)))
+ }
+ }
+
context := map[string]any{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
if 512 < len(ops) {
disableCache()