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

This commit is contained in:
Liang Ding 2023-01-23 11:20:05 +08:00
parent 6141be700a
commit 6ed1c5dc1c
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
12 changed files with 11 additions and 184 deletions

View file

@ -17,15 +17,10 @@
package sql
import (
"bytes"
"crypto/sha256"
"database/sql"
"fmt"
"path"
"sync"
"time"
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/eventbus"
@ -136,23 +131,6 @@ func FlushQueue() {
if 5000 < elapsed {
logging.LogInfof("op tx [%dms]", elapsed)
}
start = time.Now()
tx, err = BeginTx()
if nil != err {
return
}
for _, box := range boxes.Values() {
if !ast.IsNodeIDPattern(box.(string)) {
continue
}
updateBoxHash(tx, box.(string))
}
CommitTx(tx)
elapsed = time.Now().Sub(start).Milliseconds()
if 1000 < elapsed {
logging.LogInfof("hash tx [%dms]", elapsed)
}
}
func mergeUpsertTrees() (ops []*treeQueueOperation) {
@ -229,28 +207,3 @@ func RemoveTreePathQueue(treeBox, treePathPrefix string) {
newOp := &treeQueueOperation{removeTreeBox: treeBox, removeTreePath: treePathPrefix, inQueueTime: time.Now(), action: "delete"}
operationQueue = append(operationQueue, newOp)
}
func updateBoxHash(tx *sql.Tx, boxID string) {
sum := boxChecksum(boxID)
PutBoxHash(tx, boxID, sum)
}
func boxChecksum(box string) (ret string) {
rows, err := query("SELECT hash FROM blocks WHERE type = 'd' AND box = ? ORDER BY id DESC", box)
if nil != err {
logging.LogErrorf("sql query failed: %s", err)
return
}
defer rows.Close()
buf := bytes.Buffer{}
for rows.Next() {
var hash string
if err = rows.Scan(&hash); nil != err {
logging.LogErrorf("query scan field failed: %s", err)
return
}
buf.WriteString(hash)
}
ret = fmt.Sprintf("%x", sha256.Sum256(buf.Bytes()))
return
}