Skip to content

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

:art: 同一个块中引用多个相同块时反链去重 Fix https://github.com/siyuan-note/siyuan/issues/3317

Liang Ding2cfd534bc9d3
diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go
index fc51d17a00..564c056bd9 100644
--- a/kernel/model/backlink.go
+++ b/kernel/model/backlink.go
@@ -170,6 +170,7 @@ func BuildTreeBacklink(id, keyword, mentionKeyword string, beforeLen int) (boxID
var links []*Block
refs := sql.QueryRefsByDefID(id, true)
+ refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317
// 为了减少查询,组装好 IDs 后一次查出
defSQLBlockIDs, refSQLBlockIDs := map[string]bool{}, map[string]bool{}
@@ -269,6 +270,22 @@ func BuildTreeBacklink(id, keyword, mentionKeyword string, beforeLen int) (boxID
return
}
+func removeDuplicatedRefs(refs []*sql.Ref) (ret []*sql.Ref) {
+ for _, ref := range refs {
+ contain := false
+ for _, r := range ret {
+ if ref.DefBlockID == r.DefBlockID && ref.BlockID == r.BlockID {
+ contain = true
+ break
+ }
+ }
+ if !contain {
+ ret = append(ret, ref)
+ }
+ }
+ return
+}
+
func buildTreeBackmention(defSQLBlock *sql.Block, refBlocks []*Block, keyword string, excludeBacklinkIDs *hashset.Set, beforeLen int) (ret []*Block) {
ret = []*Block{}