Skip to content

Commit

Permalink
🎨 改进内核任务调度机制提升稳定性 #7113
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jan 24, 2023
1 parent e8fe3a7 commit c5f4d3c
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 28 deletions.
10 changes: 10 additions & 0 deletions app/appearance/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions app/appearance/langs/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions app/appearance/langs/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion app/appearance/langs/zh_CHT.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "隱藏主窗口",
Expand Down Expand Up @@ -1062,4 +1072,4 @@
"184": "由<a href=\"https://b3log.org/siyuan\" target=\"_blank\">思源筆記</a>強力驅動",
"185": "索引校驗完畢"
}
}
},
10 changes: 10 additions & 0 deletions app/appearance/langs/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "隐藏主窗口",
Expand Down
1 change: 1 addition & 0 deletions kernel/api/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion kernel/mobile/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package mobile

import (
"fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"os"
"path/filepath"
"strings"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"io/ioutil"
"os"
"path"
Expand All @@ -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"
)
Expand Down
18 changes: 9 additions & 9 deletions kernel/model/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -125,6 +125,7 @@ func InitConf() {
Conf.Lang = util.Lang
}
}
util.Lang = Conf.Lang
}

Conf.Langs = loadLangs()
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/model/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package model
import (
"errors"
"fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"math"
"os"
"path"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package model
import (
"encoding/json"
"fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"io/fs"
"math"
"os"
Expand All @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package model

import (
"fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"strings"
"time"

Expand All @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/ocr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import (
"github.com/siyuan-note/siyuan/kernel/task"
"io"
"os"
"path/filepath"
Expand All @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion kernel/model/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"math"
"net/http"
"os"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"path"
"regexp"
"sort"
Expand All @@ -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"
Expand Down
7 changes: 1 addition & 6 deletions kernel/model/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"os"
"path"
"path/filepath"
Expand All @@ -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"
)
Expand Down
10 changes: 8 additions & 2 deletions kernel/task/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" // 数据库索引队列
Expand All @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions kernel/util/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
)

0 comments on commit c5f4d3c

Please sign in to comment.