🎨 Improve .sy data file writing transaction https://github.com/siyuan-note/siyuan/issues/11834

This commit is contained in:
Daniel 2024-07-04 11:17:31 +08:00
parent 63d5a2114f
commit abc3eb76c5
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -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 {