From e48680200c7d611d2d08002a4c7e93ac95031361 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 12 Jan 2025 11:57:24 +0800 Subject: [PATCH] :art: Backlink count at the doc block title including sub-blocks https://github.com/siyuan-note/siyuan/issues/13791 --- kernel/model/push_reload.go | 25 ++++++++++++++++++------- kernel/util/websocket.go | 4 ++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/kernel/model/push_reload.go b/kernel/model/push_reload.go index 906f00040..767b33672 100644 --- a/kernel/model/push_reload.go +++ b/kernel/model/push_reload.go @@ -151,14 +151,25 @@ func refreshRefCount(rootID, blockID string) { return } - refCounts := sql.QueryRootChildrenRefCount(bt.RootID) - refCount := refCounts[blockID] - var rootRefCount int - for _, count := range refCounts { - rootRefCount += count + isDoc := bt.ID == bt.RootID + var rootRefIDs []string + var refCount, rootRefCount int + refIDs, _ := sql.QueryRefIDsByDefID(bt.ID, isDoc) + if isDoc { + rootRefIDs = refIDs + } else { + rootRefIDs, _ = sql.QueryRefIDsByDefID(bt.RootID, true) } - refIDs, _, _, _ := GetBlockRefs(blockID, false) - util.PushSetDefRefCount(rootID, blockID, refIDs, refCount, rootRefCount) + refCount = len(refIDs) + rootRefCount = len(rootRefIDs) + var defIDs []string + if isDoc { + defIDs = sql.QueryChildDefIDsByRootDefID(bt.ID) + } else { + defIDs = append(defIDs, bt.ID) + } + + util.PushSetDefRefCount(rootID, blockID, refIDs, rootRefIDs, defIDs, refCount, rootRefCount) } // refreshDynamicRefText 用于刷新块引用的动态锚文本。 diff --git a/kernel/util/websocket.go b/kernel/util/websocket.go index b01f007fc..2bce8851c 100644 --- a/kernel/util/websocket.go +++ b/kernel/util/websocket.go @@ -271,8 +271,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, refIDs []string, refCount, rootRefCount int) { - BroadcastByType("main", "setDefRefCount", 0, "", map[string]interface{}{"rootID": rootID, "blockID": blockID, "refCount": refCount, "rootRefCount": rootRefCount, "refIDs": refIDs}) +func PushSetDefRefCount(rootID, blockID string, refIDs, rootRefIDs, defIDs []string, refCount, rootRefCount int) { + BroadcastByType("main", "setDefRefCount", 0, "", map[string]interface{}{"rootID": rootID, "blockID": blockID, "refCount": refCount, "rootRefCount": rootRefCount, "refIDs": refIDs, "rootRefIDs": rootRefIDs, "defIDs": defIDs}) } func PushProtyleLoading(rootID, msg string) {