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

This commit is contained in:
Liang Ding 2023-01-26 19:50:56 +08:00
parent 2e773ade52
commit 0a2d095d00
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 60 additions and 6 deletions

View file

@ -20,6 +20,7 @@ import (
"bytes"
"database/sql"
"errors"
"fmt"
"os"
"path/filepath"
"regexp"
@ -982,6 +983,42 @@ func deleteByRootID(tx *sql.Tx, rootID string, context map[string]interface{}) (
return
}
func batchDeleteByRootIDs(tx *sql.Tx, rootIDs []string, context map[string]interface{}) (err error) {
ids := strings.Join(rootIDs, "','")
ids = "('" + ids + "')"
stmt := "DELETE FROM blocks WHERE root_id IN " + ids
if err = execStmtTx(tx, stmt); nil != err {
return
}
stmt = "DELETE FROM blocks_fts WHERE root_id IN " + ids
if err = execStmtTx(tx, stmt); nil != err {
return
}
stmt = "DELETE FROM blocks_fts_case_insensitive WHERE root_id IN " + ids
if err = execStmtTx(tx, stmt); nil != err {
return
}
stmt = "DELETE FROM spans WHERE root_id IN " + ids
if err = execStmtTx(tx, stmt); nil != err {
return
}
stmt = "DELETE FROM assets WHERE root_id IN " + ids
if err = execStmtTx(tx, stmt); nil != err {
return
}
stmt = "DELETE FROM refs WHERE root_id IN " + ids
if err = execStmtTx(tx, stmt); nil != err {
return
}
stmt = "DELETE FROM file_annotation_refs WHERE root_id IN " + ids
if err = execStmtTx(tx, stmt); nil != err {
return
}
ClearBlockCache()
eventbus.Publish(eventbus.EvtSQLDeleteBlocks, context, fmt.Sprintf("%d", len(rootIDs)))
return
}
func batchDeleteByPathPrefix(tx *sql.Tx, boxID, pathPrefix string) (err error) {
stmt := "DELETE FROM blocks WHERE box = ? AND path LIKE ?"
if err = execStmtTx(tx, stmt, boxID, pathPrefix+"%"); nil != err {