Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-01-25 11:43:09 +08:00
commit 981e598149
26 changed files with 203 additions and 108 deletions

View file

@ -864,6 +864,17 @@
"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",
"task.database.index.commit": "Execute database index commit",
"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",

View file

@ -864,6 +864,17 @@
"xy": "%d años %s",
"max": "mucho tiempo %s"
},
"_taskAction": {
"task.repo.checkout": "Ejecutar el pago desde la instantánea",
"task.database.index.full": "Ejecutar índice de reconstrucción",
"task.database.index": "Ejecutar el índice de la base de datos",
"task.database.index.commit": "Ejecutar la confirmación del índice de la base de datos",
"task.database.index.ref": "Ejecutar referencia de índice de base de datos",
"task.database.index.fix": "Ejecutar 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",

View file

@ -864,6 +864,17 @@
"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": "Effectuer l'indexation de la base de données",
"task.database.index.commit": "Effectuer la validation de l'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",

View file

@ -864,6 +864,17 @@
"xy": "%d 年%s",
"max": "很久%s"
},
"_taskAction": {
"task.repo.checkout": "執行從快照中檢出",
"task.database.index.full": "執行重建索引",
"task.database.index": "執行數據庫索引",
"task.database.index.commit": "執行數據庫索引提交",
"task.database.index.ref": "執行數據庫索引引用",
"task.database.index.fix": "執行數據庫索引訂正",
"task.ocr.image": "執行圖片 OCR 提取文本",
"task.history.generateDoc": "執行生成文件歷史",
"task.database.index.embedBlock": "執行數據庫索引嵌入塊"
},
"_trayMenu": {
"showWindow": "顯示主窗口",
"hideWindow": "隱藏主窗口",
@ -1062,4 +1073,4 @@
"184": "由<a href=\"https://b3log.org/siyuan\" target=\"_blank\">思源筆記</a>強力驅動",
"185": "索引校驗完畢"
}
}
},

View file

@ -864,6 +864,17 @@
"xy": "%d 年%s",
"max": "很久%s"
},
"_taskAction": {
"task.repo.checkout": "执行从快照中检出",
"task.database.index.full": "执行重建索引",
"task.database.index": "执行数据库索引",
"task.database.index.commit": "执行数据库索引提交",
"task.database.index.ref": "执行数据库索引引用",
"task.database.index.fix": "执行数据库索引订正",
"task.ocr.image": "执行图片 OCR 提取文本",
"task.history.generateDoc": "执行生成文件历史",
"task.database.index.embedBlock": "执行数据库索引嵌入块"
},
"_trayMenu": {
"showWindow": "显示主窗口",
"hideWindow": "隐藏主窗口",

View file

@ -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()

View file

@ -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"

View file

@ -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"
)

View file

@ -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"
@ -106,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 {
@ -126,6 +125,7 @@ func InitConf() {
Conf.Lang = util.Lang
}
}
util.Lang = Conf.Lang
}
Conf.Langs = loadLangs()
@ -141,6 +141,7 @@ func InitConf() {
}
if !langOK {
Conf.Lang = "en_US"
util.Lang = Conf.Lang
}
Conf.Appearance.Lang = Conf.Lang
if nil == Conf.UILayout {
@ -322,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)
@ -364,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)
}
@ -422,7 +421,6 @@ func Close(force bool, execInstallPkg int) (exitCode int) {
}
}
task.CloseWait()
Conf.Close()
sql.CloseDatabase()
treenode.SaveBlockTree(false)
@ -569,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
}

View file

@ -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},

View file

@ -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"
)
@ -524,11 +524,10 @@ func clearOutdatedHistoryDir(historyDir string) {
p := strings.TrimPrefix(dir, util.HistoryDir)
p = filepath.ToSlash(p[1:])
if txErr = sql.DeleteHistoriesByPathPrefix(tx, dir); nil != txErr {
sql.RollbackTx(tx)
logging.LogErrorf("delete history [%s] failed: %s", dir, txErr)
return
}
if txErr = sql.CommitTx(tx); nil != txErr {
if txErr = sql.CommitHistoryTx(tx); nil != txErr {
logging.LogErrorf("commit history tx failed: %s", txErr)
return
}
@ -683,10 +682,9 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) {
}
if err := sql.InsertHistories(tx, histories); nil != err {
logging.LogErrorf("insert histories failed: %s", err)
sql.RollbackTx(tx)
return
}
if err := sql.CommitTx(tx); nil != err {
if err := sql.CommitHistoryTx(tx); nil != err {
logging.LogErrorf("commit transaction failed: %s", err)
return
}

View file

@ -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"
)

View file

@ -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"
)

View file

@ -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"

View file

@ -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"

View file

@ -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) {

View file

@ -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"
)
@ -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
}
}
}

View file

@ -94,12 +94,12 @@ func docTitleImgAsset(root *ast.Node) *Asset {
func DeleteAssetsByHashes(hashes []string) {
sqlStmt := "DELETE FROM assets WHERE hash IN ('" + strings.Join(hashes, "','") + "') OR hash = ''"
tx, err := BeginTx()
tx, err := beginTx()
if nil != err {
return
}
execStmtTx(tx, sqlStmt)
CommitTx(tx)
commitTx(tx)
}
func QueryAssetByHash(hash string) (ret *Asset) {

View file

@ -46,27 +46,28 @@ type Block struct {
Updated string
}
func updateRootContent(tx *sql.Tx, content, updated, id string) {
func updateRootContent(tx *sql.Tx, content, updated, id string) (err error) {
stmt := "UPDATE blocks SET content = ?, fcontent = ?, updated = ? WHERE id = ?"
if err := execStmtTx(tx, stmt, content, content, updated, id); nil != err {
if err = execStmtTx(tx, stmt, content, content, updated, id); nil != err {
return
}
stmt = "UPDATE blocks_fts SET content = ?, fcontent = ?, updated = ? WHERE id = ?"
if err := execStmtTx(tx, stmt, content, content, updated, id); nil != err {
if err = execStmtTx(tx, stmt, content, content, updated, id); nil != err {
return
}
if !caseSensitive {
stmt = "UPDATE blocks_fts_case_insensitive SET content = ?, fcontent = ?, updated = ? WHERE id = ?"
if err := execStmtTx(tx, stmt, content, content, updated, id); nil != err {
if err = execStmtTx(tx, stmt, content, content, updated, id); nil != err {
return
}
}
removeBlockCache(id)
cache.RemoveBlockIAL(id)
return
}
func UpdateBlockContent(block *Block) {
tx, err := BeginTx()
tx, err := beginTx()
if nil != err {
return
}
@ -93,7 +94,7 @@ func UpdateBlockContent(block *Block) {
}
func DeleteTree(table, rootID string) {
tx, err := BeginTx()
tx, err := beginTx()
if nil != err {
return
}

View file

@ -37,13 +37,13 @@ type Ref struct {
Type string
}
func UpsertRefs(tx *sql.Tx, tree *parse.Tree) {
if err := deleteRefsByPath(tx, tree.Box, tree.Path); nil != err {
func upsertRefs(tx *sql.Tx, tree *parse.Tree) (err error) {
if err = deleteRefsByPath(tx, tree.Box, tree.Path); nil != err {
return
}
if err := deleteFileAnnotationRefsByPath(tx, tree.Box, tree.Path); nil != err {
if err = deleteFileAnnotationRefsByPath(tx, tree.Box, tree.Path); nil != err {
return
}
insertRef(tx, tree)
err = insertRefs(tx, tree)
return
}

View file

@ -785,7 +785,7 @@ func DeleteBlockByIDs(tx *sql.Tx, ids []string) (err error) {
return deleteBlocksByIDs(tx, ids)
}
func DeleteByBoxTx(tx *sql.Tx, box string) (err error) {
func deleteByBoxTx(tx *sql.Tx, box string) (err error) {
if err = deleteBlocksByBoxTx(tx, box); nil != err {
return
}
@ -798,7 +798,7 @@ func DeleteByBoxTx(tx *sql.Tx, box string) (err error) {
if err = deleteAttributesByBoxTx(tx, box); nil != err {
return
}
if err = deleteRefsByBoxTx(tx, box); nil != err {
if err = deleteBlockRefsByBoxTx(tx, box); nil != err {
return
}
if err = deleteFileAnnotationRefsByBoxTx(tx, box); nil != err {
@ -914,14 +914,14 @@ func deleteRefsByPathTx(tx *sql.Tx, box, path string) (err error) {
return
}
func DeleteRefsByBoxTx(tx *sql.Tx, box string) (err error) {
func deleteRefsByBoxTx(tx *sql.Tx, box string) (err error) {
if err = deleteFileAnnotationRefsByBoxTx(tx, box); nil != err {
return
}
return deleteRefsByBoxTx(tx, box)
return deleteBlockRefsByBoxTx(tx, box)
}
func deleteRefsByBoxTx(tx *sql.Tx, box string) (err error) {
func deleteBlockRefsByBoxTx(tx *sql.Tx, box string) (err error) {
stmt := "DELETE FROM refs WHERE box = ?"
err = execStmtTx(tx, stmt, box)
return
@ -945,7 +945,7 @@ func deleteFileAnnotationRefsByBoxTx(tx *sql.Tx, box string) (err error) {
return
}
func DeleteByRootID(tx *sql.Tx, rootID string) (err error) {
func deleteByRootID(tx *sql.Tx, rootID string) (err error) {
stmt := "DELETE FROM blocks WHERE root_id = ?"
if err = execStmtTx(tx, stmt, rootID); nil != err {
return
@ -1049,7 +1049,7 @@ func query(query string, args ...interface{}) (*sql.Rows, error) {
return db.Query(query, args...)
}
func BeginTx() (tx *sql.Tx, err error) {
func beginTx() (tx *sql.Tx, err error) {
if tx, err = db.Begin(); nil != err {
logging.LogErrorf("begin tx failed: %s\n %s", err, logging.ShortStack())
if strings.Contains(err.Error(), "database is locked") {
@ -1069,7 +1069,7 @@ func BeginHistoryTx() (tx *sql.Tx, err error) {
return
}
func CommitTx(tx *sql.Tx) (err error) {
func CommitHistoryTx(tx *sql.Tx) (err error) {
if nil == tx {
logging.LogErrorf("tx is nil")
return errors.New("tx is nil")
@ -1081,10 +1081,16 @@ func CommitTx(tx *sql.Tx) (err error) {
return
}
func RollbackTx(tx *sql.Tx) {
if err := tx.Rollback(); nil != err {
logging.LogErrorf("rollback tx failed: %s\n %s", err, logging.ShortStack())
func commitTx(tx *sql.Tx) (err error) {
if nil == tx {
logging.LogErrorf("tx is nil")
return errors.New("tx is nil")
}
if err = tx.Commit(); nil != err {
logging.LogErrorf("commit tx failed: %s\n %s", err, logging.ShortStack())
}
return
}
func prepareExecInsertTx(tx *sql.Tx, stmtSQL string, args []interface{}) (err error) {

View file

@ -50,7 +50,7 @@ type dbQueueOperation struct {
func AutoFlushTx() {
for {
time.Sleep(util.SQLFlushInterval)
task.PrependTask(task.DatabaseIndex, FlushQueue)
task.PrependTask(task.DatabaseIndexCommit, FlushQueue)
}
}
@ -97,43 +97,69 @@ func FlushQueue() {
txLock.Lock()
defer txLock.Unlock()
start := time.Now()
tx, err := BeginTx()
tx, err := beginTx()
if nil != err {
return
}
context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
for _, op := range ops {
execOps := 0
for i, op := range ops {
if util.IsExiting {
break
}
switch op.action {
case "upsert":
tree := op.upsertTree
if err = upsertTree(tx, tree, context); nil != err {
logging.LogErrorf("upsert tree [%s] into database failed: %s", tree.Box+tree.Path, err)
}
err = upsertTree(tx, op.upsertTree, context)
case "delete":
batchDeleteByPathPrefix(tx, op.removeTreeBox, op.removeTreePath)
err = batchDeleteByPathPrefix(tx, op.removeTreeBox, op.removeTreePath)
case "delete_id":
DeleteByRootID(tx, op.removeTreeID)
err = deleteByRootID(tx, op.removeTreeID)
case "rename":
batchUpdateHPath(tx, op.renameTree.Box, op.renameTree.ID, op.renameTreeOldHPath, op.renameTree.HPath)
updateRootContent(tx, path.Base(op.renameTree.HPath), op.renameTree.Root.IALAttr("updated"), op.renameTree.ID)
err = batchUpdateHPath(tx, op.renameTree.Box, op.renameTree.ID, op.renameTreeOldHPath, op.renameTree.HPath)
if nil != err {
break
}
err = updateRootContent(tx, path.Base(op.renameTree.HPath), op.renameTree.Root.IALAttr("updated"), op.renameTree.ID)
case "delete_box":
DeleteByBoxTx(tx, op.box)
err = deleteByBoxTx(tx, op.box)
case "delete_box_refs":
DeleteRefsByBoxTx(tx, op.box)
err = deleteRefsByBoxTx(tx, op.box)
case "insert_refs":
InsertRefs(tx, op.upsertTree)
err = insertRefs(tx, op.upsertTree)
case "update_refs":
UpsertRefs(tx, op.upsertTree)
err = upsertRefs(tx, op.upsertTree)
default:
logging.LogErrorf("unknown operation [%s]", op.action)
break
}
execOps++
if nil != err {
logging.LogErrorf("queue operation failed: %s", err)
break
}
if 0 < i && 0 == i%64 {
if err = commitTx(tx); nil != err {
logging.LogErrorf("commit tx failed: %s", err)
break
}
execOps = 0
tx, err = beginTx()
if nil != err {
break
}
}
}
if 0 < execOps {
if err = commitTx(tx); nil != err {
logging.LogErrorf("commit tx failed: %s", err)
}
}
CommitTx(tx)
elapsed := time.Now().Sub(start).Milliseconds()
if 5000 < elapsed {
logging.LogInfof("op tx [%dms]", elapsed)

View file

@ -43,15 +43,14 @@ func getDatabaseVer() (ret string) {
func setDatabaseVer() {
key := "siyuan_database_ver"
tx, err := BeginTx()
tx, err := beginTx()
if nil != err {
return
}
if err = putStat(tx, key, util.DatabaseVer); nil != err {
RollbackTx(tx)
return
}
CommitTx(tx)
commitTx(tx)
}
func putStat(tx *sql.Tx, key, value string) (err error) {

View file

@ -26,7 +26,6 @@ import (
"github.com/88250/lute/parse"
"github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/eventbus"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -36,12 +35,6 @@ func init() {
luteEngine.RenderOptions.KramdownBlockIAL = false // 数据库 markdown 字段为标准 md但是要保留 span block ial
}
func InsertRefs(tx *sql.Tx, tree *parse.Tree) {
if err := insertRef(tx, tree); nil != err {
logging.LogErrorf("insert refs tree [%s] into database failed: %s", tree.Box+tree.Path, err)
}
}
const (
BlocksInsert = "INSERT INTO blocks (id, parent_id, root_id, hash, box, path, hpath, name, alias, memo, tag, content, fcontent, markdown, length, type, subtype, ial, sort, created, updated) VALUES %s"
BlocksFTSInsert = "INSERT INTO blocks_fts (id, parent_id, root_id, hash, box, path, hpath, name, alias, memo, tag, content, fcontent, markdown, length, type, subtype, ial, sort, created, updated) VALUES %s"
@ -285,7 +278,7 @@ func insertSpans0(tx *sql.Tx, bulk []*Span) (err error) {
return
}
func insertRefs(tx *sql.Tx, refs []*Ref) (err error) {
func insertBlockRefs(tx *sql.Tx, refs []*Ref) (err error) {
if 1 > len(refs) {
return
}
@ -388,9 +381,9 @@ func insertFileAnnotationRefs0(tx *sql.Tx, bulk []*FileAnnotationRef) (err error
return
}
func insertRef(tx *sql.Tx, tree *parse.Tree) (err error) {
func insertRefs(tx *sql.Tx, tree *parse.Tree) (err error) {
refs, fileAnnotationRefs := refsFromTree(tree)
if err = insertRefs(tx, refs); nil != err {
if err = insertBlockRefs(tx, refs); nil != err {
return
}
if err = insertFileAnnotationRefs(tx, fileAnnotationRefs); nil != err {
@ -450,7 +443,7 @@ func upsertTree(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (e
}
refs, fileAnnotationRefs := refsFromTree(tree)
if err = insertRefs(tx, refs); nil != err {
if err = insertBlockRefs(tx, refs); nil != err {
return
}
if err = insertFileAnnotationRefs(tx, fileAnnotationRefs); nil != err {

View file

@ -29,7 +29,6 @@ var (
taskQueue []*Task
taskQueueStatus int
queueLock = sync.Mutex{}
taskLock = sync.Mutex{}
)
const (
@ -53,7 +52,6 @@ func PrependTask(action string, handler interface{}, args ...interface{}) {
return
}
cancelTask(action)
taskQueue = append([]*Task{newTask(action, handler, args...)}, taskQueue...)
}
@ -66,7 +64,6 @@ func AppendTask(action string, handler interface{}, args ...interface{}) {
return
}
cancelTask(action)
taskQueue = append(taskQueue, newTask(action, handler, args...))
}
@ -74,10 +71,6 @@ func CancelTask(actions ...string) {
queueLock.Lock()
defer queueLock.Unlock()
cancelTask(actions...)
}
func cancelTask(actions ...string) {
for i := len(taskQueue) - 1; i >= 0; i-- {
task := taskQueue[i]
for _, action := range actions {
@ -99,10 +92,10 @@ 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" // 数据库索引队列
DatabaseIndex = "task.database.index" // 数据库索引
DatabaseIndexCommit = "task.database.index.commit" // 数据库索引提交
DatabaseIndexRef = "task.database.index.ref" // 数据库索引引用
DatabaseIndexFix = "task.database.index.fix" // 数据库索引订正
OCRImage = "task.ocr.image" // 图片 OCR 提取文本
@ -121,8 +114,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)
}
@ -137,6 +137,8 @@ func StatusLoop() {
}
}
var taskWaitGroup = sync.WaitGroup{}
func Loop() {
for {
time.Sleep(10 * time.Millisecond)
@ -154,17 +156,9 @@ func Loop() {
break
}
execTask(task)
}
}
func CloseWait() {
taskQueueStatus = QueueStatusClosing
for {
time.Sleep(10 * time.Millisecond)
if 1 > len(taskQueue) {
break
}
taskWaitGroup.Add(1)
go execTask(task)
taskWaitGroup.Wait()
}
}
@ -189,8 +183,6 @@ func popTask() (ret *Task) {
}
func execTask(task *Task) {
taskLock.Lock()
defer taskLock.Unlock()
defer logging.Recover()
args := make([]reflect.Value, len(task.Args))
@ -201,5 +193,7 @@ func execTask(task *Task) {
args[i] = reflect.ValueOf(v)
}
}
task.Handler.Call(args)
taskWaitGroup.Done()
}

View file

@ -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{}{}
)