mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-10 22:52:34 +01:00
🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113
This commit is contained in:
parent
c1ff45f4a4
commit
7d1b50116b
14 changed files with 51 additions and 52 deletions
|
|
@ -497,6 +497,10 @@ func genTreeID(tree *parse.Tree) {
|
|||
return
|
||||
}
|
||||
|
||||
func ReloadUI() {
|
||||
task.AppendTask(task.ReloadUI, util.ReloadUI)
|
||||
}
|
||||
|
||||
func FullReindex() {
|
||||
task.PrependTask(task.DatabaseIndexFull, fullReindex)
|
||||
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
|
||||
|
|
@ -518,12 +522,6 @@ func fullReindex() {
|
|||
}
|
||||
treenode.SaveBlockTree(true)
|
||||
LoadFlashcards()
|
||||
|
||||
util.PushMsg(Conf.Language(58), 7000)
|
||||
go func() {
|
||||
time.Sleep(1 * time.Second)
|
||||
util.ReloadUI()
|
||||
}()
|
||||
}
|
||||
|
||||
func ChangeBoxSort(boxIDs []string) {
|
||||
|
|
|
|||
|
|
@ -243,6 +243,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
|
||||
FullReindex()
|
||||
IncSync()
|
||||
ReloadUI()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -298,6 +299,7 @@ func RollbackNotebookHistory(historyPath string) (err error) {
|
|||
|
||||
FullReindex()
|
||||
IncSync()
|
||||
ReloadUI()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -441,6 +441,7 @@ func ImportData(zipPath string) (err error) {
|
|||
|
||||
IncSync()
|
||||
FullReindex()
|
||||
ReloadUI()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -706,13 +707,6 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
return
|
||||
}
|
||||
IncSync()
|
||||
sql.WaitForWritingDatabase()
|
||||
|
||||
util.PushEndlessProgress(Conf.Language(58))
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
util.ReloadUI()
|
||||
}()
|
||||
}
|
||||
debug.FreeOSMemory()
|
||||
IncSync()
|
||||
|
|
|
|||
|
|
@ -197,16 +197,14 @@ func init() {
|
|||
// util.SetBootDetails(msg)
|
||||
// util.ContextPushMsg(context, msg)
|
||||
//})
|
||||
eventbus.Subscribe(eventbus.EvtSQLInsertBlocksFTS, func(context map[string]interface{}, current, total, blockCount int, hash string) {
|
||||
eventbus.Subscribe(eventbus.EvtSQLInsertBlocksFTS, func(context map[string]interface{}, blockCount int, hash string) {
|
||||
if util.ContainerAndroid == util.Container || util.ContainerIOS == util.Container {
|
||||
// Android/iOS 端不显示数据索引和搜索索引状态提示 https://github.com/siyuan-note/siyuan/issues/6392
|
||||
return
|
||||
}
|
||||
|
||||
if (1 > current && 1 == total) || current == total-1 {
|
||||
current = total
|
||||
}
|
||||
|
||||
current := context["current"]
|
||||
total := context["total"]
|
||||
msg := fmt.Sprintf(Conf.Language(90), current, total, blockCount, hash)
|
||||
util.SetBootDetails(msg)
|
||||
util.ContextPushMsg(context, msg)
|
||||
|
|
|
|||
|
|
@ -540,6 +540,7 @@ func checkoutRepo(id string) {
|
|||
}
|
||||
|
||||
FullReindex()
|
||||
ReloadUI()
|
||||
|
||||
if syncEnabled {
|
||||
func() {
|
||||
|
|
@ -1025,12 +1026,15 @@ func syncRepo(exit, byHand bool) (err error) {
|
|||
cache.ClearDocsIAL() // 同步后文档树文档图标没有更新 https://github.com/siyuan-note/siyuan/issues/4939
|
||||
if needFullReindex(upsertTrees) { // 改进同步后全量重建索引判断 https://github.com/siyuan-note/siyuan/issues/5764
|
||||
FullReindex()
|
||||
if !exit {
|
||||
ReloadUI()
|
||||
}
|
||||
return
|
||||
}
|
||||
incReindex(upserts, removes)
|
||||
|
||||
incReindex(upserts, removes)
|
||||
if !exit {
|
||||
util.ReloadUI()
|
||||
ReloadUI()
|
||||
}
|
||||
|
||||
elapsed = time.Since(start)
|
||||
|
|
|
|||
|
|
@ -251,11 +251,6 @@ func incReindex(upserts, removes []string) {
|
|||
treenode.IndexBlockTree(tree)
|
||||
sql.UpsertTreeQueue(tree)
|
||||
}
|
||||
|
||||
util.PushStatusBar(Conf.Language(58))
|
||||
if needPushRemoveProgress || needPushUpsertProgress {
|
||||
util.PushEndlessProgress(Conf.Language(58))
|
||||
}
|
||||
}
|
||||
|
||||
func SetCloudSyncDir(name string) {
|
||||
|
|
|
|||
|
|
@ -114,7 +114,9 @@ func FlushQueue() {
|
|||
return
|
||||
}
|
||||
|
||||
if err = execOp(op, tx, i, total, context); nil != err {
|
||||
context["current"] = i
|
||||
context["total"] = total
|
||||
if err = execOp(op, tx, context); nil != err {
|
||||
logging.LogErrorf("queue operation failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -131,12 +133,12 @@ func FlushQueue() {
|
|||
}
|
||||
}
|
||||
|
||||
func execOp(op *dbQueueOperation, tx *sql.Tx, current, total int, context map[string]interface{}) (err error) {
|
||||
func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (err error) {
|
||||
switch op.action {
|
||||
case "index":
|
||||
err = indexTree(tx, op.box, op.indexPath, current, total, context)
|
||||
err = indexTree(tx, op.box, op.indexPath, context)
|
||||
case "upsert":
|
||||
err = upsertTree(tx, op.upsertTree, current, total, context)
|
||||
err = upsertTree(tx, op.upsertTree, context)
|
||||
case "delete":
|
||||
err = batchDeleteByPathPrefix(tx, op.removeTreeBox, op.removeTreePath)
|
||||
case "delete_id":
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ const (
|
|||
FileAnnotationRefsPlaceholder = "(?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||
)
|
||||
|
||||
func insertBlocks(tx *sql.Tx, blocks []*Block, current, total int, context map[string]interface{}) (err error) {
|
||||
func insertBlocks(tx *sql.Tx, blocks []*Block, context map[string]interface{}) (err error) {
|
||||
if 1 > len(blocks) {
|
||||
return
|
||||
}
|
||||
|
|
@ -63,20 +63,20 @@ func insertBlocks(tx *sql.Tx, blocks []*Block, current, total int, context map[s
|
|||
continue
|
||||
}
|
||||
|
||||
if err = insertBlocks0(tx, bulk, current, total, context); nil != err {
|
||||
if err = insertBlocks0(tx, bulk, context); nil != err {
|
||||
return
|
||||
}
|
||||
bulk = []*Block{}
|
||||
}
|
||||
if 0 < len(bulk) {
|
||||
if err = insertBlocks0(tx, bulk, current, total, context); nil != err {
|
||||
if err = insertBlocks0(tx, bulk, context); nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func insertBlocks0(tx *sql.Tx, bulk []*Block, current, total int, context map[string]interface{}) (err error) {
|
||||
func insertBlocks0(tx *sql.Tx, bulk []*Block, context map[string]interface{}) (err error) {
|
||||
valueStrings := make([]string, 0, len(bulk))
|
||||
valueArgs := make([]interface{}, 0, len(bulk)*strings.Count(BlocksPlaceholder, "?"))
|
||||
hashBuf := bytes.Buffer{}
|
||||
|
|
@ -129,7 +129,7 @@ func insertBlocks0(tx *sql.Tx, bulk []*Block, current, total int, context map[st
|
|||
}
|
||||
hashBuf.WriteString("fts")
|
||||
evtHash = fmt.Sprintf("%x", sha256.Sum256(hashBuf.Bytes()))[:7]
|
||||
eventbus.Publish(eventbus.EvtSQLInsertBlocksFTS, context, current, total, len(bulk), evtHash)
|
||||
eventbus.Publish(eventbus.EvtSQLInsertBlocksFTS, context, len(bulk), evtHash)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -393,24 +393,24 @@ func insertRefs(tx *sql.Tx, tree *parse.Tree) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func indexTree(tx *sql.Tx, box, p string, current, total int, context map[string]interface{}) (err error) {
|
||||
func indexTree(tx *sql.Tx, box, p string, context map[string]interface{}) (err error) {
|
||||
tree, err := filesys.LoadTree(box, p, luteEngine)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
err = insertTree(tx, tree, current, total, context)
|
||||
err = insertTree(tx, tree, context)
|
||||
return
|
||||
}
|
||||
|
||||
func insertTree(tx *sql.Tx, tree *parse.Tree, current, total int, context map[string]interface{}) (err error) {
|
||||
func insertTree(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
|
||||
blocks, spans, assets, attributes := fromTree(tree.Root, tree)
|
||||
refs, fileAnnotationRefs := refsFromTree(tree)
|
||||
err = insertTree0(tx, tree, current, total, context, blocks, spans, assets, attributes, refs, fileAnnotationRefs)
|
||||
err = insertTree0(tx, tree, context, blocks, spans, assets, attributes, refs, fileAnnotationRefs)
|
||||
return
|
||||
}
|
||||
|
||||
func upsertTree(tx *sql.Tx, tree *parse.Tree, current, total int, context map[string]interface{}) (err error) {
|
||||
func upsertTree(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
|
||||
oldBlockHashes := queryBlockHashes(tree.ID)
|
||||
blocks, spans, assets, attributes := fromTree(tree.Root, tree)
|
||||
newBlockHashes := map[string]string{}
|
||||
|
|
@ -460,16 +460,16 @@ func upsertTree(tx *sql.Tx, tree *parse.Tree, current, total int, context map[st
|
|||
}
|
||||
|
||||
refs, fileAnnotationRefs := refsFromTree(tree)
|
||||
if err = insertTree0(tx, tree, current, total, context, blocks, spans, assets, attributes, refs, fileAnnotationRefs); nil != err {
|
||||
if err = insertTree0(tx, tree, context, blocks, spans, assets, attributes, refs, fileAnnotationRefs); nil != err {
|
||||
return
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func insertTree0(tx *sql.Tx, tree *parse.Tree, current, total int, context map[string]interface{},
|
||||
func insertTree0(tx *sql.Tx, tree *parse.Tree, context map[string]interface{},
|
||||
blocks []*Block, spans []*Span, assets []*Asset, attributes []*Attribute,
|
||||
refs []*Ref, fileAnnotationRefs []*FileAnnotationRef) (err error) {
|
||||
if err = insertBlocks(tx, blocks, current, total, context); nil != err {
|
||||
if err = insertBlocks(tx, blocks, context); nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ const (
|
|||
OCRImage = "task.ocr.image" // 图片 OCR 提取文本
|
||||
HistoryGenerateDoc = "task.history.generateDoc" // 生成文件历史
|
||||
DatabaseIndexEmbedBlock = "task.database.index.embedBlock" // 数据库索引嵌入块
|
||||
ReloadUI = "task.reload.ui" // 重载 UI
|
||||
)
|
||||
|
||||
func ContainIndexTask() bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue