mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-14 11:14:21 +01:00
🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113
This commit is contained in:
parent
a83a08bdb5
commit
72093f7e2e
7 changed files with 103 additions and 70 deletions
|
|
@ -40,24 +40,19 @@ import (
|
|||
func RefreshBacklink(id string) {
|
||||
WaitForWritingFiles()
|
||||
|
||||
tx, err := sql.BeginTx()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
defer sql.CommitTx(tx)
|
||||
|
||||
refs := sql.QueryRefsByDefID(id, false)
|
||||
trees := map[string]*parse.Tree{}
|
||||
for _, ref := range refs {
|
||||
tree := trees[ref.RootID]
|
||||
if nil == tree {
|
||||
tree, err = loadTreeByBlockID(ref.RootID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("refresh tree refs failed: %s", err)
|
||||
var loadErr error
|
||||
tree, loadErr = loadTreeByBlockID(ref.RootID)
|
||||
if nil != loadErr {
|
||||
logging.LogErrorf("refresh tree refs failed: %s", loadErr)
|
||||
continue
|
||||
}
|
||||
trees[ref.RootID] = tree
|
||||
sql.UpsertRefs(tx, tree)
|
||||
sql.UpdateRefsTreeQueue(tree)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -482,6 +482,7 @@ func genTreeID(tree *parse.Tree) {
|
|||
|
||||
func FullReindex() {
|
||||
task.PrependTask(task.DatabaseIndexFull, fullReindex)
|
||||
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
|
||||
}
|
||||
|
||||
func fullReindex() {
|
||||
|
|
@ -501,7 +502,6 @@ func fullReindex() {
|
|||
for _, openedBox := range openedBoxes {
|
||||
index(openedBox.ID)
|
||||
}
|
||||
IndexRefs()
|
||||
treenode.SaveBlockTree(true)
|
||||
LoadFlashcards()
|
||||
|
||||
|
|
|
|||
|
|
@ -1459,12 +1459,6 @@ func createDoc(boxID, p, title, dom string) (err error) {
|
|||
transaction := &Transaction{DoOperations: []*Operation{{Action: "create", Data: tree}}}
|
||||
err = PerformTransactions(&[]*Transaction{transaction})
|
||||
if nil != err {
|
||||
tx, txErr := sql.BeginTx()
|
||||
if nil != txErr {
|
||||
logging.LogFatalf("transaction failed: %s", txErr)
|
||||
return
|
||||
}
|
||||
sql.CommitTx(tx)
|
||||
logging.LogFatalf("transaction failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,18 +39,14 @@ func (box *Box) Unindex() {
|
|||
}
|
||||
|
||||
func unindex(boxID string) {
|
||||
tx, err := sql.BeginTx()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
sql.DeleteByBoxTx(tx, boxID)
|
||||
sql.CommitTx(tx)
|
||||
ids := treenode.RemoveBlockTreesByBoxID(boxID)
|
||||
RemoveRecentDoc(ids)
|
||||
sql.DeleteBoxQueue(boxID)
|
||||
}
|
||||
|
||||
func (box *Box) Index() {
|
||||
task.PrependTask(task.DatabaseIndex, index, box.ID)
|
||||
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
|
||||
}
|
||||
|
||||
func index(boxID string) {
|
||||
|
|
@ -94,12 +90,12 @@ func index(boxID string) {
|
|||
}
|
||||
|
||||
cache.PutDocIAL(file.path, docIAL)
|
||||
treenode.IndexBlockTree(tree)
|
||||
sql.UpsertTreeQueue(tree)
|
||||
|
||||
util.IncBootProgress(bootProgressPart, fmt.Sprintf(Conf.Language(92), util.ShortPathForBootingDisplay(tree.Path)))
|
||||
treeSize += file.size
|
||||
treeCount++
|
||||
treenode.IndexBlockTree(tree)
|
||||
if 1 < i && 0 == i%64 {
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(88), i, len(files)-i))
|
||||
}
|
||||
|
|
@ -128,16 +124,12 @@ func IndexRefs() {
|
|||
for _, refBlock := range refBlocks {
|
||||
refTreeIDs.Add(refBlock.RootID)
|
||||
}
|
||||
|
||||
if 0 < refTreeIDs.Size() {
|
||||
luteEngine := NewLute()
|
||||
bootProgressPart := 10.0 / float64(refTreeIDs.Size())
|
||||
for _, box := range Conf.GetOpenedBoxes() {
|
||||
tx, err := sql.BeginTx()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
sql.DeleteRefsByBoxTx(tx, box.ID)
|
||||
sql.CommitTx(tx)
|
||||
sql.DeleteBoxRefsQueue(box.ID)
|
||||
|
||||
files := box.ListFiles("/")
|
||||
i := 0
|
||||
|
|
@ -163,14 +155,7 @@ func IndexRefs() {
|
|||
continue
|
||||
}
|
||||
|
||||
tx, err = sql.BeginTx()
|
||||
if nil != err {
|
||||
continue
|
||||
}
|
||||
sql.InsertRefs(tx, tree)
|
||||
if err = sql.CommitTx(tx); nil != err {
|
||||
continue
|
||||
}
|
||||
sql.InsertRefsTreeQueue(tree)
|
||||
if 1 < i && 0 == i%64 {
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(55), i))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,7 +196,6 @@ func Mount(boxID string) (alreadyMount bool, err error) {
|
|||
box.SaveConf(boxConf)
|
||||
|
||||
box.Index()
|
||||
IndexRefs()
|
||||
// 缓存根一级的文档树展开
|
||||
ListDocTree(box.ID, "/", Conf.FileTree.Sort)
|
||||
treenode.SaveBlockTree(false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue