mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113
This commit is contained in:
parent
981e598149
commit
b5fc879628
4 changed files with 32 additions and 4 deletions
|
|
@ -105,7 +105,7 @@ func index(boxID string) {
|
||||||
|
|
||||||
cache.PutDocIAL(file.path, docIAL)
|
cache.PutDocIAL(file.path, docIAL)
|
||||||
treenode.ReindexBlockTree(tree)
|
treenode.ReindexBlockTree(tree)
|
||||||
sql.UpsertTreeQueue(tree)
|
sql.IndexTreeQueue(box.ID, file.path)
|
||||||
|
|
||||||
util.IncBootProgress(bootProgressPart, fmt.Sprintf(Conf.Language(92), util.ShortPathForBootingDisplay(tree.Path)))
|
util.IncBootProgress(bootProgressPart, fmt.Sprintf(Conf.Language(92), util.ShortPathForBootingDisplay(tree.Path)))
|
||||||
treeSize += file.size
|
treeSize += file.size
|
||||||
|
|
|
||||||
|
|
@ -1447,7 +1447,7 @@ func reindexTree0(tree *parse.Tree, i, size int) {
|
||||||
indexWriteJSONQueue(tree)
|
indexWriteJSONQueue(tree)
|
||||||
} else {
|
} else {
|
||||||
treenode.ReindexBlockTree(tree)
|
treenode.ReindexBlockTree(tree)
|
||||||
sql.UpsertTreeQueue(tree)
|
sql.IndexTreeQueue(tree.Box, tree.Path)
|
||||||
}
|
}
|
||||||
util.PushStatusBar(fmt.Sprintf(Conf.Language(183), i, size, html.EscapeHTMLStr(path.Base(tree.HPath))))
|
util.PushStatusBar(fmt.Sprintf(Conf.Language(183), i, size, html.EscapeHTMLStr(path.Base(tree.HPath))))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,13 @@ var (
|
||||||
|
|
||||||
type dbQueueOperation struct {
|
type dbQueueOperation struct {
|
||||||
inQueueTime time.Time
|
inQueueTime time.Time
|
||||||
action string // upsert/delete/delete_id/rename/delete_box/delete_box_refs/insert_refs
|
action string // upsert/delete/delete_id/rename/delete_box/delete_box_refs/insert_refs/index
|
||||||
|
|
||||||
|
indexPath string // index
|
||||||
upsertTree *parse.Tree // upsert/insert_refs
|
upsertTree *parse.Tree // upsert/insert_refs
|
||||||
removeTreeBox, removeTreePath string // delete
|
removeTreeBox, removeTreePath string // delete
|
||||||
removeTreeIDBox, removeTreeID string // delete_id
|
removeTreeIDBox, removeTreeID string // delete_id
|
||||||
box string // delete_box/delete_box_refs
|
box string // delete_box/delete_box_refs/index
|
||||||
renameTree *parse.Tree // rename
|
renameTree *parse.Tree // rename
|
||||||
renameTreeOldHPath string // rename
|
renameTreeOldHPath string // rename
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +111,8 @@ func FlushQueue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch op.action {
|
switch op.action {
|
||||||
|
case "index":
|
||||||
|
err = indexTree(tx, op.box, op.indexPath, context)
|
||||||
case "upsert":
|
case "upsert":
|
||||||
err = upsertTree(tx, op.upsertTree, context)
|
err = upsertTree(tx, op.upsertTree, context)
|
||||||
case "delete":
|
case "delete":
|
||||||
|
|
@ -231,6 +234,20 @@ func DeleteBoxQueue(boxID string) {
|
||||||
operationQueue = append(operationQueue, newOp)
|
operationQueue = append(operationQueue, newOp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IndexTreeQueue(box, p string) {
|
||||||
|
dbQueueLock.Lock()
|
||||||
|
defer dbQueueLock.Unlock()
|
||||||
|
|
||||||
|
newOp := &dbQueueOperation{indexPath: p, box: box, inQueueTime: time.Now(), action: "index"}
|
||||||
|
for i, op := range operationQueue {
|
||||||
|
if "index" == op.action && op.indexPath == p && op.box == box { // 相同树则覆盖
|
||||||
|
operationQueue[i] = newOp
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
operationQueue = append(operationQueue, newOp)
|
||||||
|
}
|
||||||
|
|
||||||
func UpsertTreeQueue(tree *parse.Tree) {
|
func UpsertTreeQueue(tree *parse.Tree) {
|
||||||
dbQueueLock.Lock()
|
dbQueueLock.Lock()
|
||||||
defer dbQueueLock.Unlock()
|
defer dbQueueLock.Unlock()
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
|
|
@ -392,6 +393,16 @@ func insertRefs(tx *sql.Tx, tree *parse.Tree) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func indexTree(tx *sql.Tx, box, p string, context map[string]interface{}) (err error) {
|
||||||
|
tree, err := filesys.LoadTree(box, p, luteEngine)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = upsertTree(tx, tree, context)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func upsertTree(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
|
func upsertTree(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
|
||||||
oldBlockHashes := queryBlockHashes(tree.ID)
|
oldBlockHashes := queryBlockHashes(tree.ID)
|
||||||
blocks, spans, assets, attributes := fromTree(tree.Root, tree)
|
blocks, spans, assets, attributes := fromTree(tree.Root, tree)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue