🐛 退出应用时数据库未完全写入 https://github.com/siyuan-note/siyuan/issues/6318
This commit is contained in:
parent
4ae5698ea6
commit
db04bfa572
5 changed files with 27 additions and 12 deletions
|
@ -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)
|
||||
|
|
|
@ -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{}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue