Skip to content

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

:art: Improve dynamic anchor text auto-refresh stability https://github.com/siyuan-note/siyuan/issues/8234

Danielfa3abe615edb
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 8b37d4baab..d448acd140 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -1231,9 +1231,18 @@ func getRefDefIDs(node *ast.Node) (refDefIDs []string) {
func pushSetDefRefCount(rootID, blockID string) {
sql.WaitForWritingDatabase()
- refCounts := sql.QueryRefCount([]string{blockID})
+ bt := treenode.GetBlockTree(blockID)
+ if nil == bt {
+ return
+ }
+
+ refCounts := sql.QueryRootChildrenRefCount(bt.RootID)
refCount := refCounts[blockID]
- util.PushSetDefRefCount(rootID, blockID, refCount)
+ var rootRefCount int
+ for _, count := range refCounts {
+ rootRefCount += count
+ }
+ util.PushSetDefRefCount(rootID, blockID, refCount, rootRefCount)
}
func upsertAvBlockRel(node *ast.Node) {
diff --git a/kernel/util/websocket.go b/kernel/util/websocket.go
index ed42738151..8ca88f3e75 100644
--- a/kernel/util/websocket.go
+++ b/kernel/util/websocket.go
@@ -262,8 +262,8 @@ func PushSetRefDynamicText(rootID, blockID, defBlockID, refText string) {
BroadcastByType("main", "setRefDynamicText", 0, "", map[string]interface{}{"rootID": rootID, "blockID": blockID, "defBlockID": defBlockID, "refText": refText})
}
-func PushSetDefRefCount(rootID, blockID string, refCount int) {
- BroadcastByType("main", "setDefRefCount", 0, "", map[string]interface{}{"rootID": rootID, "blockID": blockID, "refCount": refCount})
+func PushSetDefRefCount(rootID, blockID string, refCount, rootRefCount int) {
+ BroadcastByType("main", "setDefRefCount", 0, "", map[string]interface{}{"rootID": rootID, "blockID": blockID, "refCount": refCount, "rootRefCount": rootRefCount})
}
func PushProtyleLoading(rootID, msg string) {