🧑‍💻 Add a parameter containChildren for the kernel API /api/ref/getBacklinkDoc

接口 `/api/ref/getBacklinkDoc` 和 `/api/ref/getBackmentionDoc`  添加参数 `containChildren` 。

Co-authored-by: weizelong <1710010123@qq.com>
This commit is contained in:
Misuzu2027 2024-08-21 12:26:51 +08:00 committed by GitHub
parent 380cee6e10
commit 13140edd6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 8 deletions

View file

@ -68,7 +68,7 @@ type Backlink struct {
Expand bool `json:"expand"`
}
func GetBackmentionDoc(defID, refTreeID, keyword string) (ret []*Backlink) {
func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren bool) (ret []*Backlink) {
keyword = strings.TrimSpace(keyword)
ret = []*Backlink{}
beforeLen := 12
@ -78,7 +78,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string) (ret []*Backlink) {
}
rootID := sqlBlock.RootID
refs := sql.QueryRefsByDefID(defID, true)
refs := sql.QueryRefsByDefID(defID, containChildren)
refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317
linkRefs, _, excludeBacklinkIDs := buildLinkRefs(rootID, refs, keyword)
@ -114,7 +114,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string) (ret []*Backlink) {
return
}
func GetBacklinkDoc(defID, refTreeID, keyword string) (ret []*Backlink) {
func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren bool) (ret []*Backlink) {
keyword = strings.TrimSpace(keyword)
ret = []*Backlink{}
sqlBlock := sql.GetBlock(defID)
@ -123,7 +123,7 @@ func GetBacklinkDoc(defID, refTreeID, keyword string) (ret []*Backlink) {
}
rootID := sqlBlock.RootID
tmpRefs := sql.QueryRefsByDefID(defID, true)
tmpRefs := sql.QueryRefsByDefID(defID, containChildren)
var refs []*sql.Ref
for _, ref := range tmpRefs {
if ref.RootID == refTreeID {