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/7113

Liang Ding1fec9323de7b
diff --git a/kernel/sql/queue.go b/kernel/sql/queue.go
index 0d35c54b9b..e094c3bf0e 100644
--- a/kernel/sql/queue.go
+++ b/kernel/sql/queue.go
@@ -103,7 +103,8 @@ func FlushQueue() {
}
context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
- for _, op := range ops {
+ execOps := 0
+ for i, op := range ops {
if util.IsExiting {
break
}
@@ -131,16 +132,36 @@ func FlushQueue() {
err = upsertRefs(tx, op.upsertTree)
default:
logging.LogErrorf("unknown operation [%s]", op.action)
+ break
}
+ op.renameTree = nil
+ op.upsertTree = nil
+
+ execOps++
if nil != err {
logging.LogErrorf("queue operation failed: %s", err)
break
}
+
+ if 0 < i && 0 == i%64 {
+ if err = commitTx(tx); nil != err {
+ logging.LogErrorf("commit tx failed: %s", err)
+ break
+ }
+
+ execOps = 0
+ tx, err = beginTx()
+ if nil != err {
+ break
+ }
+ }
}
- if err = commitTx(tx); nil != err {
- logging.LogErrorf("commit tx failed: %s", err)
+ if 0 < execOps {
+ if err = commitTx(tx); nil != err {
+ logging.LogErrorf("commit tx failed: %s", err)
+ }
}
elapsed := time.Now().Sub(start).Milliseconds()
if 5000 < elapsed {