From 9b4a6eb577742340114398a9df5a59d90dea0f5d Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 17 Feb 2023 15:40:40 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E9=87=8D=E5=BB=BA=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E9=81=AE=E7=BD=A9=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/7386?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/history.go | 3 ++- kernel/sql/queue_history.go | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/kernel/model/history.go b/kernel/model/history.go index 074843121..8182aa88d 100644 --- a/kernel/model/history.go +++ b/kernel/model/history.go @@ -582,8 +582,9 @@ func ReindexHistory() (err error) { name := historyDir.Name() indexHistoryDir(name, lutEngine) - util.PushEndlessProgress(fmt.Sprintf(Conf.Language(40), name)) } + + sql.WaitForWritingHistoryDatabase() return } diff --git a/kernel/sql/queue_history.go b/kernel/sql/queue_history.go index 35666f313..998933387 100644 --- a/kernel/sql/queue_history.go +++ b/kernel/sql/queue_history.go @@ -59,7 +59,7 @@ func FlushHistoryQueue() { defer txLock.Unlock() start := time.Now() - context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar} + context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress} total := len(ops) for i, op := range ops { if util.IsExiting { @@ -137,3 +137,27 @@ func getHistoryOperations() (ops []*historyDBQueueOperation) { historyOperationQueue = nil return } + +func WaitForWritingHistoryDatabase() { + var printLog bool + var lastPrintLog bool + for i := 0; isWritingHistoryDatabase(); i++ { + time.Sleep(50 * time.Millisecond) + if 200 < i && !printLog { // 10s 后打日志 + logging.LogWarnf("history database is writing: \n%s", logging.ShortStack()) + printLog = true + } + if 1200 < i && !lastPrintLog { // 60s 后打日志 + logging.LogWarnf("history database is still writing") + lastPrintLog = true + } + } +} + +func isWritingHistoryDatabase() bool { + time.Sleep(util.SQLFlushInterval + 50*time.Millisecond) + if 0 < len(historyOperationQueue) || util.IsMutexLocked(&historyTxLock) { + return true + } + return false +}