mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 18:10:12 +01:00
🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113
This commit is contained in:
parent
6141be700a
commit
6ed1c5dc1c
12 changed files with 11 additions and 184 deletions
|
|
@ -65,10 +65,6 @@ func updateRootContent(tx *sql.Tx, content, updated, id string) {
|
|||
cache.RemoveBlockIAL(id)
|
||||
}
|
||||
|
||||
func InsertBlock(tx *sql.Tx, block *Block, context map[string]interface{}) (err error) {
|
||||
return insertBlocks(tx, []*Block{block}, context)
|
||||
}
|
||||
|
||||
func UpdateBlockContent(block *Block) {
|
||||
tx, err := BeginTx()
|
||||
if nil != err {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,27 +54,6 @@ func setDatabaseVer() {
|
|||
CommitTx(tx)
|
||||
}
|
||||
|
||||
func ClearBoxHash(tx *sql.Tx) {
|
||||
stmt := "DELETE FROM stat WHERE `key` LIKE '%_hash'"
|
||||
execStmtTx(tx, stmt)
|
||||
}
|
||||
|
||||
func RemoveBoxHash(tx *sql.Tx, box string) {
|
||||
key := box + "_hash"
|
||||
stmt := "DELETE FROM stat WHERE `key` = '" + key + "'"
|
||||
execStmtTx(tx, stmt)
|
||||
}
|
||||
|
||||
func PutBoxHash(tx *sql.Tx, box, hash string) {
|
||||
key := box + "_hash"
|
||||
putStat(tx, key, hash)
|
||||
}
|
||||
|
||||
func GetBoxHash(box string) string {
|
||||
key := box + "_hash"
|
||||
return getStat(key)
|
||||
}
|
||||
|
||||
func putStat(tx *sql.Tx, key, value string) (err error) {
|
||||
stmt := "DELETE FROM stat WHERE `key` = '" + key + "'"
|
||||
if err = execStmtTx(tx, stmt); nil != err {
|
||||
|
|
|
|||
|
|
@ -36,13 +36,6 @@ func init() {
|
|||
luteEngine.RenderOptions.KramdownBlockIAL = false // 数据库 markdown 字段为标准 md,但是要保留 span block ial
|
||||
}
|
||||
|
||||
func InsertBlocksSpans(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
|
||||
if err = insertBlocksSpans(tx, tree, context); nil != err {
|
||||
logging.LogErrorf("insert tree [%s] into database failed: %s", tree.Box+tree.Path, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func InsertRefs(tx *sql.Tx, tree *parse.Tree) {
|
||||
if err := insertRef(tx, tree); nil != err {
|
||||
logging.LogErrorf("insert refs tree [%s] into database failed: %s", tree.Box+tree.Path, err)
|
||||
|
|
@ -395,23 +388,6 @@ func insertFileAnnotationRefs0(tx *sql.Tx, bulk []*FileAnnotationRef) (err error
|
|||
return
|
||||
}
|
||||
|
||||
func insertBlocksSpans(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
|
||||
blocks, spans, assets, attributes := fromTree(tree.Root, tree)
|
||||
if err = insertBlocks(tx, blocks, context); nil != err {
|
||||
return
|
||||
}
|
||||
if err = insertSpans(tx, spans); nil != err {
|
||||
return
|
||||
}
|
||||
if err = insertAssets(tx, assets); nil != err {
|
||||
return
|
||||
}
|
||||
if err = insertAttributes(tx, attributes); nil != err {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func insertRef(tx *sql.Tx, tree *parse.Tree) (err error) {
|
||||
refs, fileAnnotationRefs := refsFromTree(tree)
|
||||
if err = insertRefs(tx, refs); nil != err {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue