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 Dingc5f4d3c780d8
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index ba110df750..62354dc791 100644
--- a/app/appearance/langs/en_US.json
+++ b/app/appearance/langs/en_US.json
@@ -864,6 +864,16 @@
"xy": "%d years %s",
"max": "a long while %s"
},
+ "_taskAction": {
+ "task.repo.checkout": "Execute checkout from snapshot",
+ "task.database.index.full": "Execute rebuild index",
+ "task.database.index": "Execute database index queue",
+ "task.database.index.ref": "Execute database index reference",
+ "task.database.index.fix": "Execute database index fix",
+ "task.ocr.image": "Execute image OCR to extract text",
+ "task.history.generateDoc": "Execute GenerateDoc History",
+ "task.database.index.embedBlock": "Execute database index embed block"
+ },
"_trayMenu": {
"showWindow": "Show Window",
"hideWindow": "Hide Window",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index 4fd6cb0aab..c780a5d2e4 100644
--- a/app/appearance/langs/es_ES.json
+++ b/app/appearance/langs/es_ES.json
@@ -864,6 +864,16 @@
"xy": "%d años %s",
"max": "mucho tiempo %s"
},
+ "_taskAction": {
+ "task.repo.checkout": "Realizar el pago desde la instantánea",
+ "task.database.index.full": "Ejecutar índice de reconstrucción",
+ "task.database.index": "Ejecutar cola de índice de base de datos",
+ "task.database.index.ref": "Ejecutar referencia de índice de base de datos",
+ "task.database.index.fix": "Realizar corrección del índice de la base de datos",
+ "task.ocr.image": "Ejecutar OCR de imagen para extraer texto",
+ "task.history.generateDoc": "Ejecutar Historial GenerateDoc",
+ "task.database.index.embedBlock": "Ejecutar bloque de incrustación de índice de base de datos"
+ },
"_trayMenu": {
"showWindow": "Mostrar ventana",
"hideWindow": "Ocultar ventana",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index 14a9189e08..be351ebc11 100644
--- a/app/appearance/langs/fr_FR.json
+++ b/app/appearance/langs/fr_FR.json
@@ -864,6 +864,16 @@
"xy": "%d ans %s",
"max": "un bon moment %s"
},
+ "_taskAction": {
+ "task.repo.checkout": "Effectuer le paiement à partir d'un instantané",
+ "task.database.index.full": "Exécuter l'index de reconstruction",
+ "task.database.index": "Exécuter la file d'attente d'index de la base de données",
+ "task.database.index.ref": "Exécuter la référence d'index de la base de données",
+ "task.database.index.fix": "Effectuer la correction de l'index de la base de données",
+ "task.ocr.image": "Exécute l'OCR d'image pour extraire le texte",
+ "task.history.generateDoc": "Exécuter l'historique de GenerateDoc",
+ "task.database.index.embedBlock": "Exécuter le bloc d'intégration d'index de base de données"
+ },
"_trayMenu": {
"showWindow": "Afficher la fenêtre principale",
"hideWindow": "Masquer la fenêtre principale",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index 9609b8d4de..dcb717b1b6 100644
--- a/app/appearance/langs/zh_CHT.json
+++ b/app/appearance/langs/zh_CHT.json
@@ -864,6 +864,16 @@
"xy": "%d 年%s",
"max": "很久%s"
},
+ "_taskAction": {
+ "task.repo.checkout": "執行從快照中檢出",
+ "task.database.index.full": "執行重建索引",
+ "task.database.index": "執行數據庫索引隊列",
+ "task.database.index.ref": "執行數據庫索引引用",
+ "task.database.index.fix": "執行數據庫索引訂正",
+ "task.ocr.image": "執行圖片 OCR 提取文本",
+ "task.history.generateDoc": "執行生成文件歷史",
+ "task.database.index.embedBlock": "執行數據庫索引嵌入塊"
+ },
"_trayMenu": {
"showWindow": "顯示主窗口",
"hideWindow": "隱藏主窗口",
@@ -1062,4 +1072,4 @@
"184": "由<a href=\"https://b3log.org/siyuan\" target=\"_blank\">思源筆記</a>強力驅動",
"185": "索引校驗完畢"
}
-}
+},
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index 127b1839a6..232e2dd34b 100644
--- a/app/appearance/langs/zh_CN.json
+++ b/app/appearance/langs/zh_CN.json
@@ -864,6 +864,16 @@
"xy": "%d 年%s",
"max": "很久%s"
},
+ "_taskAction": {
+ "task.repo.checkout": "执行从快照中检出",
+ "task.database.index.full": "执行重建索引",
+ "task.database.index": "执行数据库索引队列",
+ "task.database.index.ref": "执行数据库索引引用",
+ "task.database.index.fix": "执行数据库索引订正",
+ "task.ocr.image": "执行图片 OCR 提取文本",
+ "task.history.generateDoc": "执行生成文件历史",
+ "task.database.index.embedBlock": "执行数据库索引嵌入块"
+ },
"_trayMenu": {
"showWindow": "显示主窗口",
"hideWindow": "隐藏主窗口",
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index 3848dd3262..78f26b1fb1 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -271,6 +271,7 @@ func setAppearance(c *gin.Context) {
model.Conf.Appearance = appearance
model.Conf.Lang = appearance.Lang
+ util.Lang = model.Conf.Lang
model.Conf.Save()
model.InitAppearance()
diff --git a/kernel/mobile/kernel.go b/kernel/mobile/kernel.go
index 5a5fa4f839..c764793605 100644
--- a/kernel/mobile/kernel.go
+++ b/kernel/mobile/kernel.go
@@ -18,6 +18,7 @@ package mobile
import (
"fmt"
+ "github.com/siyuan-note/siyuan/kernel/task"
"os"
"path/filepath"
"strings"
@@ -27,7 +28,6 @@ import (
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/server"
"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/mobile/bind"
diff --git a/kernel/model/box.go b/kernel/model/box.go
index 121fd4f3e8..163860adb7 100644
--- a/kernel/model/box.go
+++ b/kernel/model/box.go
@@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
+ "github.com/siyuan-note/siyuan/kernel/task"
"io/ioutil"
"os"
"path"
@@ -39,7 +40,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"
)
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index a8a31ebec9..e0c57b9f65 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -105,7 +105,7 @@ func InitConf() {
if userLang, err := locale.Detect(); nil == err {
var supportLangs []language.Tag
- for lang := range langs {
+ for lang := range util.Langs {
if tag, err := language.Parse(lang); nil == err {
supportLangs = append(supportLangs, tag)
} else {
@@ -125,6 +125,7 @@ func InitConf() {
Conf.Lang = util.Lang
}
}
+ util.Lang = Conf.Lang
}
Conf.Langs = loadLangs()
@@ -140,6 +141,7 @@ func InitConf() {
}
if !langOK {
Conf.Lang = "en_US"
+ util.Lang = Conf.Lang
}
Conf.Appearance.Lang = Conf.Lang
if nil == Conf.UILayout {
@@ -321,9 +323,6 @@ func InitConf() {
util.SetNetworkProxy(Conf.System.NetworkProxy.String())
}
-var langs = map[string]map[int]string{}
-var timeLangs = map[string]map[string]interface{}{}
-
func initLang() {
p := filepath.Join(util.WorkingDir, "appearance", "langs")
dir, err := os.Open(p)
@@ -363,14 +362,15 @@ func initLang() {
}
kernelMap[-1] = label
name := langName[:strings.LastIndex(langName, ".")]
- langs[name] = kernelMap
+ util.Langs[name] = kernelMap
- timeLangs[name] = langMap["_time"].(map[string]interface{})
+ util.TimeLangs[name] = langMap["_time"].(map[string]interface{})
+ util.TaskActionLangs[name] = langMap["_taskAction"].(map[string]interface{})
}
}
func loadLangs() (ret []*conf.Lang) {
- for name, langMap := range langs {
+ for name, langMap := range util.Langs {
lang := &conf.Lang{Label: langMap[-1], Name: name}
ret = append(ret, lang)
}
@@ -567,11 +567,11 @@ func (conf *AppConf) GetClosedBoxes() (ret []*Box) {
}
func (conf *AppConf) Language(num int) (ret string) {
- ret = langs[conf.Lang][num]
+ ret = util.Langs[conf.Lang][num]
if "" != ret {
return
}
- ret = langs["en_US"][num]
+ ret = util.Langs["en_US"][num]
return
}
diff --git a/kernel/model/file.go b/kernel/model/file.go
index 7ef46f5406..5d40e28c7a 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -19,6 +19,7 @@ package model
import (
"errors"
"fmt"
+ "github.com/siyuan-note/siyuan/kernel/task"
"math"
"os"
"path"
@@ -43,7 +44,6 @@ import (
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/search"
"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"
)
@@ -97,7 +97,7 @@ func (box *Box) docFromFileInfo(fileInfo *FileInfo, ial map[string]string) (ret
}
func HumanizeTime(then time.Time) string {
- labels := timeLangs[Conf.Lang]
+ labels := util.TimeLangs[Conf.Lang]
defaultMagnitudes := []humanize.RelTimeMagnitude{
{time.Second, labels["now"].(string), time.Second},
diff --git a/kernel/model/history.go b/kernel/model/history.go
index 44cfe23cdd..86d54ab9c6 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -19,6 +19,7 @@ package model
import (
"encoding/json"
"fmt"
+ "github.com/siyuan-note/siyuan/kernel/task"
"io/fs"
"math"
"os"
@@ -38,7 +39,6 @@ import (
"github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/search"
"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"
)
diff --git a/kernel/model/index.go b/kernel/model/index.go
index d02c1a78c7..662167154c 100644
--- a/kernel/model/index.go
+++ b/kernel/model/index.go
@@ -18,6 +18,7 @@ package model
import (
"fmt"
+ "github.com/siyuan-note/siyuan/kernel/task"
"strings"
"time"
@@ -29,7 +30,6 @@ import (
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/filesys"
"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"
)
diff --git a/kernel/model/ocr.go b/kernel/model/ocr.go
index bbd15a27d3..7be0e52e54 100644
--- a/kernel/model/ocr.go
+++ b/kernel/model/ocr.go
@@ -1,6 +1,7 @@
package model
import (
+ "github.com/siyuan-note/siyuan/kernel/task"
"io"
"os"
"path/filepath"
@@ -15,7 +16,6 @@ import (
"github.com/panjf2000/ants/v2"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/cache"
- "github.com/siyuan-note/siyuan/kernel/task"
"github.com/siyuan-note/siyuan/kernel/util"
)
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index c65660a62b..2f43befb88 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -23,6 +23,7 @@ import (
"encoding/base64"
"errors"
"fmt"
+ "github.com/siyuan-note/siyuan/kernel/task"
"math"
"net/http"
"os"
@@ -49,7 +50,6 @@ import (
"github.com/siyuan-note/siyuan/kernel/cache"
"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"
"github.com/studio-b12/gowebdav"
diff --git a/kernel/model/search.go b/kernel/model/search.go
index 6b17322d5f..243db19d4d 100644
--- a/kernel/model/search.go
+++ b/kernel/model/search.go
@@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
+ "github.com/siyuan-note/siyuan/kernel/task"
"path"
"regexp"
"sort"
@@ -38,7 +39,6 @@ import (
"github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/search"
"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"
"github.com/xrash/smetrics"
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index 037e2e7fd3..bad72ad104 100644
--- a/kernel/model/sync.go
+++ b/kernel/model/sync.go
@@ -32,7 +32,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"
)
@@ -92,12 +91,8 @@ func BootSyncData() {
}
func SyncData(boot, exit, byHand bool) {
- if !checkSync(boot, exit, byHand) {
- return
- }
-
util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)
- task.PrependTask(task.CloudSync, syncData, boot, exit, byHand)
+ syncData(boot, exit, byHand)
}
func syncData(boot, exit, byHand bool) {
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index f468c3fcf3..1ab9c79801 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
+ "github.com/siyuan-note/siyuan/kernel/task"
"os"
"path"
"path/filepath"
@@ -38,7 +39,6 @@ import (
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/cache"
"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"
)
diff --git a/kernel/task/queue.go b/kernel/task/queue.go
index 6d8c63bf7b..f9c6466585 100644
--- a/kernel/task/queue.go
+++ b/kernel/task/queue.go
@@ -98,7 +98,6 @@ func newTask(action string, handler interface{}, args ...interface{}) *Task {
}
const (
- CloudSync = "task.cloud.sync" // 数据同步
RepoCheckout = "task.repo.checkout" // 从快照中检出
DatabaseIndexFull = "task.database.index.full" // 重建索引
DatabaseIndex = "task.database.index" // 数据库索引队列
@@ -120,8 +119,15 @@ func StatusLoop() {
continue
}
+ actionLangs := util.TaskActionLangs[util.Lang]
+ action := task.Action
+ if nil != actionLangs {
+ if label := actionLangs[task.Action]; nil != label {
+ action = label.(string)
+ }
+ }
item := map[string]interface{}{
- "action": task.Action,
+ "action": action,
}
items = append(items, item)
}
diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go
index 0b2ae553a7..e38c1c5533 100644
--- a/kernel/util/runtime.go
+++ b/kernel/util/runtime.go
@@ -104,3 +104,9 @@ const (
// SQLFlushInterval 为数据库事务队列写入间隔。
SQLFlushInterval = 3000 * time.Millisecond
)
+
+var (
+ Langs = map[string]map[int]string{}
+ TimeLangs = map[string]map[string]interface{}{}
+ TaskActionLangs = map[string]map[string]interface{}{}
+)