diff --git a/kernel/model/conf.go b/kernel/model/conf.go index 92b98711f..19d47e9a6 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -353,9 +353,9 @@ var exitLock = sync.Mutex{} // force:是否不执行同步过程而直接退出 // execInstallPkg:是否执行新版本安装包 // -// 0:默认按照设置项 System.DownloadInstallPkg 检查并推送提示 -// 1:不执行新版本安装 -// 2:执行新版本安装 +// 0:默认按照设置项 System.DownloadInstallPkg 检查并推送提示 +// 1:不执行新版本安装 +// 2:执行新版本安装 func Close(force bool, execInstallPkg int) (exitCode int) { exitLock.Lock() defer exitLock.Unlock() @@ -363,7 +363,16 @@ func Close(force bool, execInstallPkg int) (exitCode int) { logging.LogInfof("exiting kernel [force=%v, execInstallPkg=%d]", force, execInstallPkg) util.PushMsg(Conf.Language(95), 10000*60) - WaitForWritingFiles() + + wg := sync.WaitGroup{} + go func() { + wg.Add(1) + time.Sleep(util.FrontendQueueInterval) + WaitForWritingFiles() + time.Sleep(50 * time.Millisecond) + sql.WaitForWritingDatabase() + wg.Done() + }() if !force { SyncData(false, true, false) if 0 != ExitSyncSucc { @@ -371,6 +380,7 @@ func Close(force bool, execInstallPkg int) (exitCode int) { return } } + wg.Wait() //util.UIProcessIDs.Range(func(key, _ interface{}) bool { // pid := key.(string) diff --git a/kernel/model/outline.go b/kernel/model/outline.go index 178ac21cc..f2aa341d8 100644 --- a/kernel/model/outline.go +++ b/kernel/model/outline.go @@ -22,10 +22,11 @@ import ( "github.com/88250/lute/ast" "github.com/emirpasic/gods/stacks/linkedliststack" "github.com/siyuan-note/siyuan/kernel/treenode" + "github.com/siyuan-note/siyuan/kernel/util" ) func Outline(rootID string) (ret []*Path, err error) { - time.Sleep(512 * time.Millisecond /* 前端队列轮询间隔 */) + time.Sleep(util.FrontendQueueInterval) WaitForWritingFiles() ret = []*Path{} diff --git a/kernel/model/search.go b/kernel/model/search.go index 3b422014f..760d119a0 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -45,7 +45,7 @@ type EmbedBlock struct { } func SearchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingMode int, breadcrumb bool) (ret []*EmbedBlock) { - time.Sleep(512 * time.Millisecond /* 前端队列轮询间隔 */) + time.Sleep(util.FrontendQueueInterval) WaitForWritingFiles() return searchEmbedBlock(embedBlockID, stmt, excludeIDs, headingMode, breadcrumb) } diff --git a/kernel/sql/queue.go b/kernel/sql/queue.go index ee1fadbd0..afc88d467 100644 --- a/kernel/sql/queue.go +++ b/kernel/sql/queue.go @@ -32,10 +32,6 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) -const ( - upsertTreesFlushDelay = 3000 -) - var ( operationQueue []*treeQueueOperation upsertTreeQueueLock = sync.Mutex{} @@ -57,7 +53,7 @@ type treeQueueOperation struct { func AutoFlushTreeQueue() { for { flushTreeQueue() - time.Sleep(time.Duration(upsertTreesFlushDelay) * time.Millisecond) + time.Sleep(util.SQLFlushInterval) } } @@ -78,7 +74,7 @@ func WaitForWritingDatabase() { } func isWritingDatabase() bool { - time.Sleep(time.Duration(upsertTreesFlushDelay+50) * time.Millisecond) + time.Sleep(util.SQLFlushInterval + 50*time.Millisecond) if 0 < len(operationQueue) || util.IsMutexLocked(&txLock) { return true } diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go index 5445c3aa2..93df3663c 100644 --- a/kernel/util/runtime.go +++ b/kernel/util/runtime.go @@ -89,3 +89,11 @@ func SetNetworkProxy(proxyURL string) { logging.LogInfof("use network proxy [%s]", proxyURL) } } + +const ( + // FrontendQueueInterval 为前端请求队列轮询间隔。 + FrontendQueueInterval = 512 * time.Millisecond + + // SQLFlushInterval 为数据库事务队列写入间隔。 + SQLFlushInterval = 3000 * time.Millisecond +)