mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 21:01:40 +08:00
🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113
This commit is contained in:
parent
981e598149
commit
b5fc879628
@ -105,7 +105,7 @@ func index(boxID string) {
|
||||
|
||||
cache.PutDocIAL(file.path, docIAL)
|
||||
treenode.ReindexBlockTree(tree)
|
||||
sql.UpsertTreeQueue(tree)
|
||||
sql.IndexTreeQueue(box.ID, file.path)
|
||||
|
||||
util.IncBootProgress(bootProgressPart, fmt.Sprintf(Conf.Language(92), util.ShortPathForBootingDisplay(tree.Path)))
|
||||
treeSize += file.size
|
||||
|
@ -1447,7 +1447,7 @@ func reindexTree0(tree *parse.Tree, i, size int) {
|
||||
indexWriteJSONQueue(tree)
|
||||
} else {
|
||||
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))))
|
||||
}
|
||||
|
@ -37,12 +37,13 @@ var (
|
||||
|
||||
type dbQueueOperation struct {
|
||||
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
|
||||
removeTreeBox, removeTreePath string // delete
|
||||
removeTreeIDBox, removeTreeID string // delete_id
|
||||
box string // delete_box/delete_box_refs
|
||||
box string // delete_box/delete_box_refs/index
|
||||
renameTree *parse.Tree // rename
|
||||
renameTreeOldHPath string // rename
|
||||
}
|
||||
@ -110,6 +111,8 @@ func FlushQueue() {
|
||||
}
|
||||
|
||||
switch op.action {
|
||||
case "index":
|
||||
err = indexTree(tx, op.box, op.indexPath, context)
|
||||
case "upsert":
|
||||
err = upsertTree(tx, op.upsertTree, context)
|
||||
case "delete":
|
||||
@ -231,6 +234,20 @@ func DeleteBoxQueue(boxID string) {
|
||||
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) {
|
||||
dbQueueLock.Lock()
|
||||
defer dbQueueLock.Unlock()
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"strings"
|
||||
|
||||
"github.com/88250/lute/parse"
|
||||
@ -392,6 +393,16 @@ func insertRefs(tx *sql.Tx, tree *parse.Tree) (err error) {
|
||||
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) {
|
||||
oldBlockHashes := queryBlockHashes(tree.ID)
|
||||
blocks, spans, assets, attributes := fromTree(tree.Root, tree)
|
||||
|
Loading…
Reference in New Issue
Block a user