From abc3eb76c57353ab7c227e89bc1f08410591bd44 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 4 Jul 2024 11:17:31 +0800 Subject: [PATCH] :art: Improve .sy data file writing transaction https://github.com/siyuan-note/siyuan/issues/11834 --- kernel/model/transaction.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 17bda1832..e7d86f515 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -72,13 +72,14 @@ func WaitForWritingFiles() { } var ( - txQueue = make(chan *Transaction, 7) - flushLock = sync.Mutex{} + txQueue = make(chan *Transaction, 7) + flushLock = sync.Mutex{} + isFlushing = false ) func isWritingFiles() bool { time.Sleep(time.Duration(50) * time.Millisecond) - return 0 < len(txQueue) + return 0 < len(txQueue) || isFlushing } func init() { @@ -95,7 +96,11 @@ func init() { func flushTx(tx *Transaction) { defer logging.Recover() flushLock.Lock() - defer flushLock.Unlock() + isFlushing = true + defer func() { + isFlushing = false + flushLock.Unlock() + }() start := time.Now() if txErr := performTx(tx); nil != txErr {