mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113
This commit is contained in:
parent
7492913ddd
commit
c1ff45f4a4
9 changed files with 54 additions and 63 deletions
|
|
@ -101,57 +101,42 @@ func FlushQueue() {
|
|||
txLock.Lock()
|
||||
defer txLock.Unlock()
|
||||
start := time.Now()
|
||||
tx, err := beginTx()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
var execOps int
|
||||
context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||
total := len(ops)
|
||||
for i, op := range ops {
|
||||
if util.IsExiting {
|
||||
return
|
||||
}
|
||||
|
||||
err = execOp(op, tx, context)
|
||||
execOps++
|
||||
|
||||
tx, err := beginTx()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
if err = execOp(op, tx, i, total, context); nil != err {
|
||||
logging.LogErrorf("queue operation failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if 0 < i && 0 == execOps%128 {
|
||||
if err = commitTx(tx); nil != err {
|
||||
logging.LogErrorf("commit tx failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
execOps = 0
|
||||
tx, err = beginTx()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if 0 < execOps {
|
||||
if err = commitTx(tx); nil != err {
|
||||
logging.LogErrorf("commit tx failed: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
elapsed := time.Now().Sub(start).Milliseconds()
|
||||
if 5000 < elapsed {
|
||||
logging.LogInfof("op tx [%dms]", elapsed)
|
||||
}
|
||||
}
|
||||
|
||||
func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (err error) {
|
||||
func execOp(op *dbQueueOperation, tx *sql.Tx, current, total int, context map[string]interface{}) (err error) {
|
||||
switch op.action {
|
||||
case "index":
|
||||
err = indexTree(tx, op.box, op.indexPath, context)
|
||||
err = indexTree(tx, op.box, op.indexPath, current, total, context)
|
||||
case "upsert":
|
||||
err = upsertTree(tx, op.upsertTree, context)
|
||||
err = upsertTree(tx, op.upsertTree, current, total, context)
|
||||
case "delete":
|
||||
err = batchDeleteByPathPrefix(tx, op.removeTreeBox, op.removeTreePath)
|
||||
case "delete_id":
|
||||
|
|
@ -171,7 +156,7 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (e
|
|||
case "update_refs":
|
||||
err = upsertRefs(tx, op.upsertTree)
|
||||
default:
|
||||
msg := fmt.Sprint("unknown operation [%s]", op.action)
|
||||
msg := fmt.Sprintf("unknown operation [%s]", op.action)
|
||||
logging.LogErrorf(msg)
|
||||
err = errors.New(msg)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue