反链面板

This commit is contained in:
Liang Ding 2022-09-29 12:38:48 +08:00
parent f6411dba9a
commit b238a5de41
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 12 additions and 23 deletions

View file

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

View file

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

View file

@ -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)