🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113

This commit is contained in:
Liang Ding 2023-01-25 12:33:38 +08:00
parent 981e598149
commit b5fc879628
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 32 additions and 4 deletions

View file

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