Skip to content

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

:art: 数据订正分步执行

Liang Dingdaaa9e67fd25
diff --git a/kernel/model/index_fix.go b/kernel/model/index_fix.go
index a63cd8d533..65b2fc920c 100644
--- a/kernel/model/index_fix.go
+++ b/kernel/model/index_fix.go
@@ -39,20 +39,27 @@ import (
// FixIndexJob 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016
func FixIndexJob() {
- task.AppendTask(task.DatabaseIndexFix, autoFixIndex)
+ task.AppendTask(task.DatabaseIndexFix, removeDuplicateDatabaseIndex)
+ sql.WaitForWritingDatabase()
+ task.AppendTask(task.DatabaseIndexFix, fixBlockTreeByFileSys)
+ sql.WaitForWritingDatabase()
+ task.AppendTask(task.DatabaseIndexFix, fixDatabaseIndexByBlockTree)
+
+ sql.WaitForWritingDatabase()
+ util.PushStatusBar(Conf.Language(185))
+ debug.FreeOSMemory()
}
var autoFixLock = sync.Mutex{}
-func autoFixIndex() {
+// removeDuplicateDatabaseIndex 删除重复的数据库索引。
+func removeDuplicateDatabaseIndex() {
defer logging.Recover()
autoFixLock.Lock()
defer autoFixLock.Unlock()
util.PushStatusBar(Conf.Language(58))
-
- // 去除重复的数据库块记录
duplicatedRootIDs := sql.GetDuplicatedRootIDs("blocks")
if 1 > len(duplicatedRootIDs) {
duplicatedRootIDs = sql.GetDuplicatedRootIDs("blocks_fts")
@@ -87,11 +94,16 @@ func autoFixIndex() {
if 0 < deletes {
logging.LogWarnf("exist more than one tree duplicated [%d], reindex it", deletes)
}
+}
+
+// fixBlockTreeByFileSys 通过文件系统订正块树。
+func fixBlockTreeByFileSys() {
+ defer logging.Recover()
+
+ autoFixLock.Lock()
+ defer autoFixLock.Unlock()
util.PushStatusBar(Conf.Language(58))
- sql.WaitForWritingDatabase()
- util.PushStatusBar(Conf.Language(58))
- // 根据文件系统补全块树
boxes := Conf.GetOpenedBoxes()
for _, box := range boxes {
boxPath := filepath.Join(util.DataDir, box.ID)
@@ -130,26 +142,23 @@ func autoFixIndex() {
}
}
- util.PushStatusBar(Conf.Language(58))
- sql.WaitForWritingDatabase()
- util.PushStatusBar(Conf.Language(58))
// 清理已关闭的笔记本块树
boxes = Conf.GetClosedBoxes()
for _, box := range boxes {
treenode.RemoveBlockTreesByBoxID(box.ID)
}
+}
+
+// fixDatabaseIndexByBlockTree 通过块树订正数据库索引。
+func fixDatabaseIndexByBlockTree() {
+ defer logging.Recover()
- // 对比块树和数据库并订正数据库
+ util.PushStatusBar(Conf.Language(58))
rootUpdatedMap := treenode.GetRootUpdated()
dbRootUpdatedMap, err := sql.GetRootUpdated()
if nil == err {
reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap)
}
-
- util.PushStatusBar(Conf.Language(58))
- sql.WaitForWritingDatabase()
- util.PushStatusBar(Conf.Language(185))
- debug.FreeOSMemory()
}
func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string) {
diff --git a/kernel/task/queue.go b/kernel/task/queue.go
index 99c3324a3f..d17391d05a 100644
--- a/kernel/task/queue.go
+++ b/kernel/task/queue.go
@@ -98,7 +98,6 @@ var uniqueActions = []string{
RepoCheckout,
DatabaseIndexFull,
DatabaseIndexCommit,
- DatabaseIndexFix,
OCRImage,
HistoryGenerateDoc,
DatabaseIndexEmbedBlock,
@@ -197,7 +196,7 @@ func execTask(task *Task) {
currentTaskAction = task.Action
- ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
ch := make(chan bool, 1)
go func() {