From 2cfd534bc9d3d4873e52ba4d6c777b331a91ca80 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 31 Jul 2022 22:33:50 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=90=8C=E4=B8=80=E4=B8=AA=E5=9D=97?= =?UTF-8?q?=E4=B8=AD=E5=BC=95=E7=94=A8=E5=A4=9A=E4=B8=AA=E7=9B=B8=E5=90=8C?= =?UTF-8?q?=E5=9D=97=E6=97=B6=E5=8F=8D=E9=93=BE=E5=8E=BB=E9=87=8D=20Fix=20?= =?UTF-8?q?https://github.com/siyuan-note/siyuan/issues/3317?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/backlink.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go index fc51d17a0..564c056bd 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{}