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 Dinge8fe3a77b352
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 519a1263c6..a8a31ebec9 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -38,7 +38,6 @@ import (
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/sql"
- "github.com/siyuan-note/siyuan/kernel/task"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
"golang.org/x/text/language"
@@ -422,7 +421,6 @@ func Close(force bool, execInstallPkg int) (exitCode int) {
}
}
- task.CloseWait()
Conf.Close()
sql.CloseDatabase()
treenode.SaveBlockTree(false)
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 0b606d13ef..f468c3fcf3 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -1303,6 +1303,13 @@ func autoFixIndex() {
}
reindexTreeByPath(box.ID, p, i, size)
+ if util.IsExiting {
+ break
+ }
+ }
+
+ if util.IsExiting {
+ break
}
}
@@ -1347,6 +1354,10 @@ func autoFixIndex() {
logging.LogWarnf("exist more than one tree [%s], reindex it", rootID)
sql.RemoveTreeQueue(root.Box, rootID)
reindexTree(rootID, i, size)
+
+ if util.IsExiting {
+ break
+ }
}
util.PushStatusBar(Conf.Language(185))
@@ -1358,6 +1369,10 @@ func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string, bl
for rootID, updated := range rootUpdatedMap {
i++
+ if util.IsExiting {
+ break
+ }
+
rootUpdated := dbRootUpdatedMap[rootID]
if "" == rootUpdated {
logging.LogWarnf("not found tree [%s] in database, reindex it", rootID)
@@ -1378,6 +1393,10 @@ func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string, bl
reindexTree(rootID, i, size)
continue
}
+
+ if util.IsExiting {
+ break
+ }
}
for rootID, _ := range dbRootUpdatedMap {
@@ -1385,6 +1404,10 @@ func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string, bl
logging.LogWarnf("tree [%s] is not in block tree, remove it from [%s]", rootID, blocksTable)
sql.DeleteTree(blocksTable, rootID)
}
+
+ if util.IsExiting {
+ break
+ }
}
}
diff --git a/kernel/task/queue.go b/kernel/task/queue.go
index fc4c6226f9..6d8c63bf7b 100644
--- a/kernel/task/queue.go
+++ b/kernel/task/queue.go
@@ -161,16 +161,6 @@ func Loop() {
}
}
-func CloseWait() {
- taskQueueStatus = QueueStatusClosing
- for {
- time.Sleep(10 * time.Millisecond)
- if 1 > len(taskQueue) {
- break
- }
- }
-}
-
func clearQueue() {
queueLock.Lock()
defer queueLock.Unlock()