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

This commit is contained in:
Liang Ding 2022-07-31 22:33:50 +08:00
parent c3f6c389fb
commit 2cfd534bc9
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -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{}