Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-01-24 15:07:34 +08:00
commit 4cd95abeae
9 changed files with 38 additions and 18 deletions

View file

@ -391,6 +391,8 @@ func getBlock(id string) (ret *Block, err error) {
return
}
waitForIndexing()
tree, err := loadTreeByBlockID(id)
if nil != err {
return

View file

@ -486,7 +486,7 @@ func FullReindex() {
}
func fullReindex() {
util.PushEndlessProgress(Conf.Language(35))
util.PushMsg(Conf.Language(35), 60*1000*10)
WaitForWritingFiles()
if err := sql.InitDatabase(true); nil != err {
@ -505,7 +505,7 @@ func fullReindex() {
treenode.SaveBlockTree(true)
LoadFlashcards()
util.PushEndlessProgress(Conf.Language(58))
util.PushMsg(Conf.Language(58), 7000)
go func() {
time.Sleep(1 * time.Second)
util.ReloadUI()

View file

@ -393,6 +393,7 @@ var exitLock = sync.Mutex{}
func Close(force bool, execInstallPkg int) (exitCode int) {
exitLock.Lock()
defer exitLock.Unlock()
util.IsExiting = true
logging.LogInfof("exiting kernel [force=%v, execInstallPkg=%d]", force, execInstallPkg)
util.PushMsg(Conf.Language(95), 10000*60)

View file

@ -49,12 +49,25 @@ func (box *Box) Index() {
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
}
var indexing = false
func waitForIndexing() {
for indexing {
time.Sleep(time.Millisecond * 100)
}
}
func index(boxID string) {
box := Conf.Box(boxID)
if nil == box {
return
}
indexing = true
defer func() {
indexing = false
}()
util.SetBootDetails("Listing files...")
files := box.ListFiles("/")
boxLen := len(Conf.GetOpenedBoxes())
@ -68,10 +81,7 @@ func index(boxID string) {
var treeCount int
var treeSize int64
i := 0
util.PushEndlessProgress(fmt.Sprintf("["+box.Name+"] "+Conf.Language(64), len(files)))
defer util.PushClearProgress()
util.PushStatusBar(fmt.Sprintf("["+box.Name+"] "+Conf.Language(64), len(files)))
for _, file := range files {
if file.isdir || !strings.HasSuffix(file.name, ".sy") {
continue
@ -101,7 +111,7 @@ func index(boxID string) {
treeSize += file.size
treeCount++
if 1 < i && 0 == i%64 {
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(88), i, len(files)-i))
util.PushStatusBar(fmt.Sprintf(Conf.Language(88), i, len(files)-i))
}
i++
}

View file

@ -1306,6 +1306,12 @@ func autoFixIndex() {
}
}
// 清理已关闭的笔记本块树
boxes = Conf.GetClosedBoxes()
for _, box := range boxes {
treenode.RemoveBlockTreesByBoxID(box.ID)
}
// 对比块树和数据库并订正数据库
rootUpdatedMap := treenode.GetRootUpdated()
dbRootUpdatedMap, err := sql.GetRootUpdated("blocks")

View file

@ -104,6 +104,10 @@ func FlushQueue() {
context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
for _, op := range ops {
if util.IsExiting {
break
}
switch op.action {
case "upsert":
tree := op.upsertTree

View file

@ -17,6 +17,7 @@
package task
import (
"github.com/siyuan-note/siyuan/kernel/util"
"reflect"
"sync"
"time"
@ -122,6 +123,10 @@ func Loop() {
continue
}
if util.IsExiting {
break
}
execTask(task)
}
}

View file

@ -292,17 +292,6 @@ func ReindexBlockTree(tree *parse.Tree) {
blockTreesLock.Lock()
defer blockTreesLock.Unlock()
var ids []string
for _, b := range blockTrees {
if b.RootID == tree.ID {
ids = append(ids, b.ID)
}
}
ids = gulu.Str.RemoveDuplicatedElem(ids)
for _, id := range ids {
delete(blockTrees, id)
}
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || !n.IsBlock() {
return ast.WalkContinue

View file

@ -42,6 +42,9 @@ const (
ExitCodeFatal = 1 // 致命错误
)
// IsExiting 是否正在退出程序。
var IsExiting = false
func logBootInfo() {
logging.LogInfof("kernel is booting:\n"+
" * ver [%s]\n"+