mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-04-26 04:48:27 -05:00
🎨 Improve sql tx queue lock https://github.com/siyuan-note/siyuan/issues/14532
This commit is contained in:
+9
-2
@@ -23,6 +23,7 @@ import (
|
||||
"path"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/88250/lute/parse"
|
||||
@@ -63,15 +64,21 @@ func ClearQueue() {
|
||||
operationQueue = nil
|
||||
}
|
||||
|
||||
var flushingTx = atomic.Bool{}
|
||||
|
||||
func FlushQueue() {
|
||||
ops := getOperations()
|
||||
total := len(ops)
|
||||
if 1 > total {
|
||||
if 1 > total && !flushingTx.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
txLock.Lock()
|
||||
defer txLock.Unlock()
|
||||
flushingTx.Store(true)
|
||||
defer func() {
|
||||
flushingTx.Store(false)
|
||||
txLock.Unlock()
|
||||
}()
|
||||
|
||||
start := time.Now()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user