Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:zap: 改进创建文档性能 Fix https://github.com/siyuan-note/siyuan/issues/7175

Liang Dingcff223bc2d94
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 923309aac5..a97f0e6296 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -64,8 +64,6 @@ func IsUnfoldHeading(transactions *[]*Transaction) bool {
var (
txQueue []*Transaction
txQueueLock = sync.Mutex{}
-
- currentTx *Transaction
)
func WaitForWritingFiles() {
@@ -86,20 +84,21 @@ func WaitForWritingFiles() {
func isWritingFiles() bool {
time.Sleep(time.Duration(20) * time.Millisecond)
- if 0 < len(txQueue) || util.IsMutexLocked(&txQueueLock) {
- return true
- }
- return nil != currentTx
+ return 0 < len(txQueue) || util.IsMutexLocked(&txQueueLock) || util.IsMutexLocked(&flushLock)
}
func FlushTxJob() {
flushTx()
}
+var flushLock = sync.Mutex{}
+
func flushTx() {
defer logging.Recover()
+ flushLock.Lock()
+ defer flushLock.Unlock()
- currentTx = mergeTx()
+ currentTx := mergeTx()
start := time.Now()
if txErr := performTx(currentTx); nil != txErr {
switch txErr.code {
@@ -119,7 +118,6 @@ func flushTx() {
logging.LogWarnf("op tx [%dms]", elapsed)
}
}
- currentTx = nil
}
func mergeTx() (ret *Transaction) {