From 2155a56a7b13b6b1df2634dd86cf6312f2d70070 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 2 Oct 2022 10:46:46 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E5=BC=8F=E5=8F=8D=E9=93=BE=E9=9D=A2=E6=9D=BF=20https://github.?= =?UTF-8?q?com/siyuan-note/siyuan/issues/3565?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/ref.go | 3 ++- kernel/model/backlink.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kernel/api/ref.go b/kernel/api/ref.go index 16dcaa86c..02b0ee37b 100644 --- a/kernel/api/ref.go +++ b/kernel/api/ref.go @@ -48,8 +48,9 @@ func getBackmentionDoc(c *gin.Context) { } defID := arg["defID"].(string) + refTreeID := arg["refTreeID"].(string) keyword := "" - backlinks := model.GetBackmentionDoc(defID, keyword) + backlinks := model.GetBackmentionDoc(defID, refTreeID, keyword) ret.Data = map[string]interface{}{ "backmentions": backlinks, } diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go index 3dca17d1d..918abb8be 100644 --- a/kernel/model/backlink.go +++ b/kernel/model/backlink.go @@ -164,7 +164,7 @@ type Backlink struct { Expand bool `json:"expand"` } -func GetBackmentionDoc(defID, keyword string) (ret []*Backlink) { +func GetBackmentionDoc(defID, refTreeID, keyword string) (ret []*Backlink) { ret = []*Backlink{} beforeLen := 12 sqlBlock := sql.GetBlock(defID) @@ -177,9 +177,15 @@ func GetBackmentionDoc(defID, keyword string) (ret []*Backlink) { refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317 linkRefs, excludeBacklinkIDs := buildLinkRefs(rootID, refs) - mentions := buildTreeBackmention(sqlBlock, linkRefs, keyword, excludeBacklinkIDs, beforeLen) + tmpMentions := buildTreeBackmention(sqlBlock, linkRefs, keyword, excludeBacklinkIDs, beforeLen) luteEngine := NewLute() treeCache := map[string]*parse.Tree{} + var mentions []*Block + for _, mention := range tmpMentions { + if mention.RootID == refTreeID { + mentions = append(mentions, mention) + } + } for _, mention := range mentions { refTree := treeCache[mention.RootID] if nil == refTree {