mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 20:31:36 +08:00
🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113
This commit is contained in:
parent
2ac8151c7a
commit
6141be700a
@ -339,22 +339,6 @@ func (box *Box) Remove(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (box *Box) Unindex() {
|
|
||||||
task.PrependTask(task.DatabaseIndex, unindex, box.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func unindex(boxID string) {
|
|
||||||
tx, err := sql.BeginTx()
|
|
||||||
if nil != err {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
sql.RemoveBoxHash(tx, boxID)
|
|
||||||
sql.DeleteByBoxTx(tx, boxID)
|
|
||||||
sql.CommitTx(tx)
|
|
||||||
ids := treenode.RemoveBlockTreesByBoxID(boxID)
|
|
||||||
RemoveRecentDoc(ids)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (box *Box) ListFiles(path string) (ret []*FileInfo) {
|
func (box *Box) ListFiles(path string) (ret []*FileInfo) {
|
||||||
fis, _, err := box.Ls(path)
|
fis, _, err := box.Ls(path)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
@ -512,7 +496,7 @@ func fullReindex() {
|
|||||||
|
|
||||||
openedBoxes := Conf.GetOpenedBoxes()
|
openedBoxes := Conf.GetOpenedBoxes()
|
||||||
for _, openedBox := range openedBoxes {
|
for _, openedBox := range openedBoxes {
|
||||||
openedBox.Index(true)
|
index(openedBox.ID, true)
|
||||||
}
|
}
|
||||||
IndexRefs()
|
IndexRefs()
|
||||||
treenode.SaveBlockTree(true)
|
treenode.SaveBlockTree(true)
|
||||||
|
@ -599,7 +599,7 @@ func InitBoxes() {
|
|||||||
box.UpdateHistoryGenerated() // 初始化历史生成时间为当前时间
|
box.UpdateHistoryGenerated() // 初始化历史生成时间为当前时间
|
||||||
|
|
||||||
if !initialized {
|
if !initialized {
|
||||||
box.Index(true)
|
index(box.ID, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/task"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -37,7 +38,32 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (box *Box) Index(fullRebuildIndex bool) (treeCount int, treeSize int64) {
|
func (box *Box) Unindex() {
|
||||||
|
task.PrependTask(task.DatabaseIndex, unindex, box.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func unindex(boxID string) {
|
||||||
|
tx, err := sql.BeginTx()
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sql.RemoveBoxHash(tx, boxID)
|
||||||
|
sql.DeleteByBoxTx(tx, boxID)
|
||||||
|
sql.CommitTx(tx)
|
||||||
|
ids := treenode.RemoveBlockTreesByBoxID(boxID)
|
||||||
|
RemoveRecentDoc(ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (box *Box) Index(fullRebuildIndex bool) {
|
||||||
|
task.PrependTask(task.DatabaseIndex, index, box.ID, fullRebuildIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
func index(boxID string, fullRebuildIndex bool) {
|
||||||
|
box := Conf.Box(boxID)
|
||||||
|
if nil == box {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
defer debug.FreeOSMemory()
|
defer debug.FreeOSMemory()
|
||||||
|
|
||||||
sql.IndexMode()
|
sql.IndexMode()
|
||||||
@ -59,7 +85,8 @@ func (box *Box) Index(fullRebuildIndex bool) (treeCount int, treeSize int64) {
|
|||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
idTitleMap := map[string]string{}
|
idTitleMap := map[string]string{}
|
||||||
idHashMap := map[string]string{}
|
idHashMap := map[string]string{}
|
||||||
|
var treeCount int
|
||||||
|
var treeSize int64
|
||||||
util.PushEndlessProgress(fmt.Sprintf("["+box.Name+"] "+Conf.Language(64), len(files)))
|
util.PushEndlessProgress(fmt.Sprintf("["+box.Name+"] "+Conf.Language(64), len(files)))
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
|
Loading…
Reference in New Issue
Block a user