Skip to content

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

:sparkles: 反链面板

Liang Dingb238a5de410c
diff --git a/kernel/api/ref.go b/kernel/api/ref.go
index aca6820cd9..89c2df0fef 100644
--- a/kernel/api/ref.go
+++ b/kernel/api/ref.go
@@ -49,9 +49,9 @@ func getBacklinkDoc(c *gin.Context) {
defID := arg["defID"].(string)
refTreeID := arg["refTreeID"].(string)
- blocks := model.GetBacklinkDoc(defID, refTreeID)
+ doms := model.GetBacklinkDoc(defID, refTreeID)
ret.Data = map[string]interface{}{
- "blocks": blocks,
+ "doms": doms,
}
}
diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go
index 61a85eefb9..9ae12bd661 100644
--- a/kernel/model/backlink.go
+++ b/kernel/model/backlink.go
@@ -158,7 +158,7 @@ OK:
return
}
-func GetBacklinkDoc(defID, refTreeID string) (ret []*Block) {
+func GetBacklinkDoc(defID, refTreeID string) (ret []string) {
keyword := ""
beforeLen := 12
sqlBlock := sql.GetBlock(defID)
@@ -168,7 +168,13 @@ func GetBacklinkDoc(defID, refTreeID string) (ret []*Block) {
rootID := sqlBlock.RootID
var links []*Block
- refs := sql.QueryRefsByDefIDRefRootID(defID, refTreeID)
+ tmpRefs := sql.QueryRefsByDefID(defID, true)
+ var refs []*sql.Ref
+ for _, ref := range tmpRefs {
+ if ref.RootID == refTreeID {
+ refs = append(refs, ref)
+ }
+ }
refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317
// 为了减少查询,组装好 IDs 后一次查出
@@ -271,10 +277,8 @@ func GetBacklinkDoc(defID, refTreeID string) (ret []*Block) {
for _, link := range linkPaths {
for _, c := range link.Children {
n := treenode.GetNodeInTree(refTree, c.ID)
- b := &Block{
- Content: lute.RenderNodeBlockDOM(n, luteEngine.ParseOptions, luteEngine.RenderOptions),
- }
- ret = append(ret, b)
+ dom := lute.RenderNodeBlockDOM(n, luteEngine.ParseOptions, luteEngine.RenderOptions)
+ ret = append(ret, dom)
}
}
return
diff --git a/kernel/sql/block_ref_query.go b/kernel/sql/block_ref_query.go
index 591ee717c4..9d7d3425b7 100644
--- a/kernel/sql/block_ref_query.go
+++ b/kernel/sql/block_ref_query.go
@@ -343,21 +343,6 @@ func QueryRefsByDefID(defBlockID string, containChildren bool) (ret []*Ref) {
return
}
-func QueryRefsByDefIDRefRootID(defBlockID, refRootBlockID string) (ret []*Ref) {
- stmt := "SELECT * FROM refs WHERE def_block_id = ? AND root_id = ?"
- rows, err := query(stmt, defBlockID, refRootBlockID)
- if nil != err {
- logging.LogErrorf("sql query failed: %s", err)
- return
- }
- defer rows.Close()
- for rows.Next() {
- ref := scanRefRows(rows)
- ret = append(ret, ref)
- }
- return
-}
-
func QueryRefsByDefIDRefID(defBlockID, refBlockID string) (ret []*Ref) {
stmt := "SELECT * FROM refs WHERE def_block_id = ? AND block_id = ?"
rows, err := query(stmt, defBlockID, refBlockID)