mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Improve graph https://github.com/siyuan-note/siyuan/issues/13040
This commit is contained in:
parent
83b932478e
commit
a48609755e
4 changed files with 10 additions and 8 deletions
|
|
@ -845,7 +845,7 @@ func buildFullLinks(condition string) (forwardlinks, backlinks []*Block) {
|
||||||
func buildDefsAndRefs(condition string) (defBlocks []*Block) {
|
func buildDefsAndRefs(condition string) (defBlocks []*Block) {
|
||||||
defBlockMap := map[string]*Block{}
|
defBlockMap := map[string]*Block{}
|
||||||
refBlockMap := map[string]*Block{}
|
refBlockMap := map[string]*Block{}
|
||||||
defRefs := sql.DefRefs(condition)
|
defRefs := sql.DefRefs(condition, Conf.Graph.MaxBlocks)
|
||||||
|
|
||||||
// 将 sql block 转为 block
|
// 将 sql block 转为 block
|
||||||
for _, row := range defRefs {
|
for _, row := range defRefs {
|
||||||
|
|
|
||||||
|
|
@ -84,10 +84,10 @@ func BuildTreeGraph(id, query string) (boxID string, nodes []*GraphNode, links [
|
||||||
var sqlBlocks []*sql.Block
|
var sqlBlocks []*sql.Block
|
||||||
var rootID string
|
var rootID string
|
||||||
if ast.NodeDocument == node.Type {
|
if ast.NodeDocument == node.Type {
|
||||||
sqlBlocks = sql.GetAllChildBlocks([]string{block.ID}, stmt)
|
sqlBlocks = sql.GetAllChildBlocks([]string{block.ID}, stmt, Conf.Graph.MaxBlocks)
|
||||||
rootID = block.ID
|
rootID = block.ID
|
||||||
} else {
|
} else {
|
||||||
sqlBlocks = sql.GetChildBlocks(block.ID, stmt)
|
sqlBlocks = sql.GetChildBlocks(block.ID, stmt, Conf.Graph.MaxBlocks)
|
||||||
}
|
}
|
||||||
blocks := fromSQLBlocks(&sqlBlocks, "", 0)
|
blocks := fromSQLBlocks(&sqlBlocks, "", 0)
|
||||||
if "" != rootID {
|
if "" != rootID {
|
||||||
|
|
@ -185,7 +185,7 @@ func BuildGraph(query string) (boxID string, nodes []*GraphNode, links []*GraphL
|
||||||
}
|
}
|
||||||
rootIDs = gulu.Str.RemoveDuplicatedElem(rootIDs)
|
rootIDs = gulu.Str.RemoveDuplicatedElem(rootIDs)
|
||||||
|
|
||||||
sqlBlocks := sql.GetAllChildBlocks(rootIDs, stmt)
|
sqlBlocks := sql.GetAllChildBlocks(rootIDs, stmt, Conf.Graph.MaxBlocks)
|
||||||
treeBlocks := fromSQLBlocks(&sqlBlocks, "", 0)
|
treeBlocks := fromSQLBlocks(&sqlBlocks, "", 0)
|
||||||
genTreeNodes(treeBlocks, &nodes, &links, false)
|
genTreeNodes(treeBlocks, &nodes, &links, false)
|
||||||
blocks = append(blocks, treeBlocks...)
|
blocks = append(blocks, treeBlocks...)
|
||||||
|
|
|
||||||
|
|
@ -726,7 +726,7 @@ func scanBlockRow(row *sql.Row) (ret *Block) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetChildBlocks(parentID, condition string) (ret []*Block) {
|
func GetChildBlocks(parentID, condition string, limit int) (ret []*Block) {
|
||||||
blockIDs := queryBlockChildrenIDs(parentID)
|
blockIDs := queryBlockChildrenIDs(parentID)
|
||||||
var params []string
|
var params []string
|
||||||
for _, id := range blockIDs {
|
for _, id := range blockIDs {
|
||||||
|
|
@ -738,6 +738,7 @@ func GetChildBlocks(parentID, condition string) (ret []*Block) {
|
||||||
if "" != condition {
|
if "" != condition {
|
||||||
sqlStmt += " AND " + condition
|
sqlStmt += " AND " + condition
|
||||||
}
|
}
|
||||||
|
sqlStmt += " LIMIT " + strconv.Itoa(limit)
|
||||||
rows, err := query(sqlStmt)
|
rows, err := query(sqlStmt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||||
|
|
@ -752,12 +753,13 @@ func GetChildBlocks(parentID, condition string) (ret []*Block) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllChildBlocks(rootIDs []string, condition string) (ret []*Block) {
|
func GetAllChildBlocks(rootIDs []string, condition string, limit int) (ret []*Block) {
|
||||||
ret = []*Block{}
|
ret = []*Block{}
|
||||||
sqlStmt := "SELECT * FROM blocks AS ref WHERE ref.root_id IN ('" + strings.Join(rootIDs, "','") + "')"
|
sqlStmt := "SELECT * FROM blocks AS ref WHERE ref.root_id IN ('" + strings.Join(rootIDs, "','") + "')"
|
||||||
if "" != condition {
|
if "" != condition {
|
||||||
sqlStmt += " AND " + condition
|
sqlStmt += " AND " + condition
|
||||||
}
|
}
|
||||||
|
sqlStmt += " LIMIT " + strconv.Itoa(limit)
|
||||||
rows, err := query(sqlStmt)
|
rows, err := query(sqlStmt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||||
|
|
|
||||||
|
|
@ -428,7 +428,7 @@ func QueryRefsByDefIDRefID(defBlockID, refBlockID string) (ret []*Ref) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefRefs(condition string) (ret []map[*Block]*Block) {
|
func DefRefs(condition string, limit int) (ret []map[*Block]*Block) {
|
||||||
ret = []map[*Block]*Block{}
|
ret = []map[*Block]*Block{}
|
||||||
stmt := "SELECT ref.*, r.block_id || '@' || r.def_block_id AS rel FROM blocks AS ref, refs AS r WHERE ref.id = r.block_id"
|
stmt := "SELECT ref.*, r.block_id || '@' || r.def_block_id AS rel FROM blocks AS ref, refs AS r WHERE ref.id = r.block_id"
|
||||||
if "" != condition {
|
if "" != condition {
|
||||||
|
|
@ -453,7 +453,7 @@ func DefRefs(condition string) (ret []map[*Block]*Block) {
|
||||||
refs[rel] = &ref
|
refs[rel] = &ref
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err = query("SELECT def.* FROM blocks AS def, refs AS r WHERE def.id = r.def_block_id")
|
rows, err = query("SELECT def.* FROM blocks AS def, refs AS r WHERE def.id = r.def_block_id LIMIT ?", limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogErrorf("sql query failed: %s", err)
|
logging.LogErrorf("sql query failed: %s", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue