Skip to content

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

:art: Improve sql tx queue lock https://github.com/siyuan-note/siyuan/issues/14532

Daniel669dfb7d58f5
diff --git a/kernel/model/tag.go b/kernel/model/tag.go
index 643198ba3a..d644352d2b 100644
--- a/kernel/model/tag.go
+++ b/kernel/model/tag.go
@@ -305,6 +305,8 @@ func SearchTags(keyword string) (ret []string) {
ret = []string{}
defer logging.Recover() // 定位 无法添加题头图标签 https://github.com/siyuan-note/siyuan/issues/6756
+ sql.FlushQueue()
+
labels := labelBlocksByKeyword(keyword)
for label := range labels {
_, t := search.MarkText(label, keyword, 1024, Conf.Search.CaseSensitive)
diff --git a/kernel/sql/queue.go b/kernel/sql/queue.go
index 5cc0787018..613306dbcc 100644
--- a/kernel/sql/queue.go
+++ b/kernel/sql/queue.go
@@ -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()