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 Dinga83a08bdb581
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index 03aaf167c4..862bbd8dea 100644
--- a/app/appearance/langs/en_US.json
+++ b/app/appearance/langs/en_US.json
@@ -928,10 +928,10 @@
"50": "Resolving reference [%s]",
"51": "Cache content block [%d]",
"52": "Every time you open the user guide notebook data will be reset, so please do not save any data in it",
- "53": "The index of [%d] documents has been completed, and [%d] remain to be processed",
+ "53": "TODO",
"54": "Indexing references...",
"55": "Indexed references of [%d] documents",
- "56": "Indexed [%d] documents",
+ "56": "TODO",
"57": "Failed to create temp key",
"58": "After the index is rebuilt, the interface will be automatically refreshed later...",
"59": "Failed to set sync ignore list",
@@ -968,7 +968,7 @@
"90": "Created [%d] of search indexes of block-level elements [%s]",
"91": "Reading block tree data...",
"92": "Parsing document tree [%s]",
- "93": "Indexing document tree [%s]",
+ "93": "TODO",
"94": "Upload failed: %s",
"95": "Exiting...",
"96": "Synchronization failed when exiting. Please manually perform a synchronization to ensure that the local data is consistent with the cloud data",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index ee55b59071..fe33478608 100644
--- a/app/appearance/langs/es_ES.json
+++ b/app/appearance/langs/es_ES.json
@@ -928,10 +928,10 @@
"50": "Resolviendo referencia [%s]",
"51": "Bloque de contenido de la caché [%d]",
"52": "Cada vez que abra la guía del usuario se restablecerán los datos del cuaderno, así que no guarde ningún dato en ella",
- "53": "Se ha completado el índice de [%d] documentos y quedan [%d] por procesar",
+ "53": "TODO",
"54": "Indexando referencias...",
"55": "Referencias indexadas de [%d] documentos",
- "56": "Documentos indexados [%d]",
+ "56": "TODO",
"57": "Fallo en la creación de la clave temporal",
"58": "Después de reconstruir el índice, la interfaz se actualizará automáticamente más tarde...",
"59": " Falló la configuración de sincronización de la lista de ignorados",
@@ -968,7 +968,7 @@
"90": "Creado [%d] de índices de búsqueda de elementos a nivel de bloque [%s]",
"91": "Leyendo datos del árbol de bloques...",
"92": "Analizando el árbol del documento [%s]",
- "93": "Árbol de documentos de indexación [%s]",
+ "93": "TODO",
"94": "Carga fallida: %s",
"95": "Saliendo...",
"96": "La sincronización falló al salir. Por favor, realice manualmente una sincronización para asegurarse de que los datos locales son coherentes con los datos de la nube",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index 6243e7af20..b8ed8b90be 100644
--- a/app/appearance/langs/fr_FR.json
+++ b/app/appearance/langs/fr_FR.json
@@ -928,10 +928,10 @@
"50": "Résolution des référence [%s]",
"51": "Blocage du contenu du cache [%d]",
"52": "Chaque fois que vous ouvrez le guide de l'utilisateur, les données du notebook seront réinitialisées, veuillez donc ne pas y enregistrer de données.",
- "53": "L'indexation de [%d] documents est terminée, et [%d] restent à traiter.",
+ "53": "TODO",
"54": "Indexation des références...",
"55": "Références indexées de [%d] documents",
- "56": "Indexé [%d] documents",
+ "56": "TODO",
"57": "Échec de la création d'une clé temporaire",
"58": "Une fois l'index reconstruit, l'interface sera automatiquement rafraîchie ultérieurement...",
"59": "Échec de la définition de la liste des ignores de synchronisation",
@@ -968,7 +968,7 @@
"90": "Création de [%d] index de recherche d'éléments de niveau bloc [%s]",
"91": "Lecture des données de l'arborescence des blocs...",
"92": "Analyse de l'arborescence du document [%s]",
- "93": "Indexation de l'arborescence du document [%s]",
+ "93": "TODO",
"94": "Échec du téléchargement : %s",
"95": "Quitter le programme...",
"96": "La synchronisation a échoué lors de la sortie. Veuillez effectuer une synchronisation manuellement pour vous assurer que les données locales sont cohérentes avec les données du cloud",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index a9862e96be..33cc0fc18d 100644
--- a/app/appearance/langs/zh_CHT.json
+++ b/app/appearance/langs/zh_CHT.json
@@ -928,10 +928,10 @@
"50": "正在解析引用 [%s]",
"51": "正在快取內容塊 [%d]",
"52": "每次打開使用者指南筆記本資料都會被重置,所以請勿在其中保存任何資料",
- "53": "已完成索引 [%d] 篇文檔,剩餘待處理 [%d]",
+ "53": "TODO",
"54": "正在索引引用關係...",
"55": "已完成索引 [%d] 篇文檔的引用關係",
- "56": "已完成索引 [%d] 篇文檔",
+ "56": "TODO",
"57": "創建臨時金鑰失敗",
"58": "重建索引完畢,稍後將自動重新整理介面...",
"59": "設置同步忽略列表失敗",
@@ -968,7 +968,7 @@
"90": "已經建立 [%d] 個塊級元素的搜索索引 [%s]",
"91": "正在讀取塊樹數據...",
"92": "正在解析文檔樹 [%s]",
- "93": "正在索引文檔樹 [%s]",
+ "93": "TODO",
"94": "上傳失敗:%s",
"95": "正在退出...",
"96": "退出時同步失敗,請手動執行一次同步以確保本地資料和雲端資料一致",
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index 00923c2767..6b497d0641 100644
--- a/app/appearance/langs/zh_CN.json
+++ b/app/appearance/langs/zh_CN.json
@@ -928,10 +928,10 @@
"50": "正在解析引用 [%s]",
"51": "正在缓存内容块 [%d]",
"52": "每次打开用户指南笔记本数据都会被重置,所以请勿在其中保存任何数据",
- "53": "已完成索引 [%d] 篇文档,剩余待处理 [%d]",
+ "53": "TODO",
"54": "正在索引引用关系...",
"55": "已完成索引 [%d] 篇文档的引用关系",
- "56": "已完成索引 [%d] 篇文档",
+ "56": "TODO",
"57": "创建临时密钥失败",
"58": "重建索引完毕,稍后将自动刷新界面...",
"59": "设置同步忽略列表失败",
@@ -968,7 +968,7 @@
"90": "已经建立 [%d] 个块级元素的搜索索引 [%s]",
"91": "正在读取块树数据...",
"92": "正在解析文档树 [%s]",
- "93": "正在索引文档树 [%s]",
+ "93": "TODO",
"94": "上传失败:%s",
"95": "正在退出...",
"96": "退出时同步失败,请手动执行一次同步以确保本地数据和云端数据一致",
diff --git a/kernel/model/box.go b/kernel/model/box.go
index da1b573070..d34867bed5 100644
--- a/kernel/model/box.go
+++ b/kernel/model/box.go
@@ -494,9 +494,12 @@ func fullReindex() {
}
treenode.InitBlockTree(true)
+ sql.IndexMode()
+ defer sql.NormalMode()
+
openedBoxes := Conf.GetOpenedBoxes()
for _, openedBox := range openedBoxes {
- index(openedBox.ID, true)
+ index(openedBox.ID)
}
IndexRefs()
treenode.SaveBlockTree(true)
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 2af166b92a..f1631195cf 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -599,7 +599,7 @@ func InitBoxes() {
box.UpdateHistoryGenerated() // 初始化历史生成时间为当前时间
if !initialized {
- index(box.ID, true)
+ index(box.ID)
}
}
diff --git a/kernel/model/index.go b/kernel/model/index.go
index cc9810a361..277f3ae85f 100644
--- a/kernel/model/index.go
+++ b/kernel/model/index.go
@@ -18,7 +18,6 @@ package model
import (
"fmt"
- "runtime/debug"
"strings"
"time"
@@ -50,51 +49,39 @@ func unindex(boxID string) {
RemoveRecentDoc(ids)
}
-func (box *Box) Index(fullRebuildIndex bool) {
- task.PrependTask(task.DatabaseIndex, index, box.ID, fullRebuildIndex)
+func (box *Box) Index() {
+ task.PrependTask(task.DatabaseIndex, index, box.ID)
}
-func index(boxID string, fullRebuildIndex bool) {
+func index(boxID string) {
box := Conf.Box(boxID)
if nil == box {
return
}
- defer debug.FreeOSMemory()
-
- sql.IndexMode()
- defer sql.NormalMode()
-
- //os.MkdirAll("pprof", 0755)
- //cpuProfile, _ := os.Create("pprof/cpu_profile_index")
- //pprof.StartCPUProfile(cpuProfile)
- //defer pprof.StopCPUProfile()
-
util.SetBootDetails("Listing files...")
files := box.ListFiles("/")
boxLen := len(Conf.GetOpenedBoxes())
if 1 > boxLen {
boxLen = 1
}
- bootProgressPart := 10.0 / float64(boxLen) / float64(len(files))
+ bootProgressPart := 30.0 / float64(boxLen) / float64(len(files))
+ start := time.Now()
luteEngine := NewLute()
var treeCount int
var treeSize int64
- util.PushEndlessProgress(fmt.Sprintf("["+box.Name+"] "+Conf.Language(64), len(files)))
-
i := 0
- // 读取并缓存路径映射
+
+ util.PushEndlessProgress(fmt.Sprintf("["+box.Name+"] "+Conf.Language(64), len(files)))
for _, file := range files {
if file.isdir || !strings.HasSuffix(file.name, ".sy") {
continue
}
- p := file.path
-
- tree, err := filesys.LoadTree(box.ID, p, luteEngine)
+ tree, err := filesys.LoadTree(box.ID, file.path, luteEngine)
if nil != err {
- logging.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, p, err)
+ logging.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, file.path, err)
continue
}
@@ -106,7 +93,8 @@ func index(boxID string, fullRebuildIndex bool) {
writeJSONQueue(tree)
}
- cache.PutDocIAL(p, docIAL)
+ cache.PutDocIAL(file.path, docIAL)
+ sql.UpsertTreeQueue(tree)
util.IncBootProgress(bootProgressPart, fmt.Sprintf(Conf.Language(92), util.ShortPathForBootingDisplay(tree.Path)))
treeSize += file.size
@@ -119,45 +107,9 @@ func index(boxID string, fullRebuildIndex bool) {
}
box.UpdateHistoryGenerated() // 初始化历史生成时间为当前时间
-
- if !fullRebuildIndex {
- return
- }
-
- // 开始重建库
-
- sql.DisableCache()
- defer sql.EnableCache()
-
- start := time.Now()
- bootProgressPart = 20.0 / float64(boxLen) / float64(treeCount)
- i = 0
- for _, file := range files {
- if file.isdir || !strings.HasSuffix(file.name, ".sy") {
- continue
- }
-
- tree, err := filesys.LoadTree(box.ID, file.path, luteEngine)
- if nil != err {
- logging.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, file.path, err)
- continue
- }
-
- util.IncBootProgress(bootProgressPart, fmt.Sprintf(Conf.Language(93), util.ShortPathForBootingDisplay(tree.Path)))
- sql.UpsertTreeQueue(tree)
- if 1 < i && 0 == i%64 {
- util.PushEndlessProgress(fmt.Sprintf("["+box.Name+"] "+Conf.Language(53), i, treeCount-i))
- }
- i++
- }
-
- sql.WaitForWritingDatabase()
-
end := time.Now()
elapsed := end.Sub(start).Seconds()
logging.LogInfof("rebuilt database for notebook [%s] in [%.2fs], tree [count=%d, size=%s]", box.ID, elapsed, treeCount, humanize.Bytes(uint64(treeSize)))
-
- util.PushEndlessProgress(fmt.Sprintf(Conf.Language(56), treeCount))
return
}
diff --git a/kernel/model/mount.go b/kernel/model/mount.go
index e3ac12ef8b..fb4e2a4b21 100644
--- a/kernel/model/mount.go
+++ b/kernel/model/mount.go
@@ -195,7 +195,7 @@ func Mount(boxID string) (alreadyMount bool, err error) {
boxConf.Closed = false
box.SaveConf(boxConf)
- box.Index(false)
+ box.Index()
IndexRefs()
// 缓存根一级的文档树展开
ListDocTree(box.ID, "/", Conf.FileTree.Sort)