🎨 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) {
|
||||
defBlockMap := map[string]*Block{}
|
||||
refBlockMap := map[string]*Block{}
|
||||
defRefs := sql.DefRefs(condition)
|
||||
defRefs := sql.DefRefs(condition, Conf.Graph.MaxBlocks)
|
||||
|
||||
// 将 sql block 转为 block
|
||||
for _, row := range defRefs {
|
||||
|
|
|
@ -84,10 +84,10 @@ func BuildTreeGraph(id, query string) (boxID string, nodes []*GraphNode, links [
|
|||
var sqlBlocks []*sql.Block
|
||||
var rootID string
|
||||
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
|
||||
} else {
|
||||
sqlBlocks = sql.GetChildBlocks(block.ID, stmt)
|
||||
sqlBlocks = sql.GetChildBlocks(block.ID, stmt, Conf.Graph.MaxBlocks)
|
||||
}
|
||||
blocks := fromSQLBlocks(&sqlBlocks, "", 0)
|
||||
if "" != rootID {
|
||||
|
@ -185,7 +185,7 @@ func BuildGraph(query string) (boxID string, nodes []*GraphNode, links []*GraphL
|
|||
}
|
||||
rootIDs = gulu.Str.RemoveDuplicatedElem(rootIDs)
|
||||
|
||||
sqlBlocks := sql.GetAllChildBlocks(rootIDs, stmt)
|
||||
sqlBlocks := sql.GetAllChildBlocks(rootIDs, stmt, Conf.Graph.MaxBlocks)
|
||||
treeBlocks := fromSQLBlocks(&sqlBlocks, "", 0)
|
||||
genTreeNodes(treeBlocks, &nodes, &links, false)
|
||||
blocks = append(blocks, treeBlocks...)
|
||||
|
|
|
@ -726,7 +726,7 @@ func scanBlockRow(row *sql.Row) (ret *Block) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetChildBlocks(parentID, condition string) (ret []*Block) {
|
||||
func GetChildBlocks(parentID, condition string, limit int) (ret []*Block) {
|
||||
blockIDs := queryBlockChildrenIDs(parentID)
|
||||
var params []string
|
||||
for _, id := range blockIDs {
|
||||
|
@ -738,6 +738,7 @@ func GetChildBlocks(parentID, condition string) (ret []*Block) {
|
|||
if "" != condition {
|
||||
sqlStmt += " AND " + condition
|
||||
}
|
||||
sqlStmt += " LIMIT " + strconv.Itoa(limit)
|
||||
rows, err := query(sqlStmt)
|
||||
if err != nil {
|
||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||
|
@ -752,12 +753,13 @@ func GetChildBlocks(parentID, condition string) (ret []*Block) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetAllChildBlocks(rootIDs []string, condition string) (ret []*Block) {
|
||||
func GetAllChildBlocks(rootIDs []string, condition string, limit int) (ret []*Block) {
|
||||
ret = []*Block{}
|
||||
sqlStmt := "SELECT * FROM blocks AS ref WHERE ref.root_id IN ('" + strings.Join(rootIDs, "','") + "')"
|
||||
if "" != condition {
|
||||
sqlStmt += " AND " + condition
|
||||
}
|
||||
sqlStmt += " LIMIT " + strconv.Itoa(limit)
|
||||
rows, err := query(sqlStmt)
|
||||
if err != nil {
|
||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||
|
|
|
@ -428,7 +428,7 @@ func QueryRefsByDefIDRefID(defBlockID, refBlockID string) (ret []*Ref) {
|
|||
return
|
||||
}
|
||||
|
||||
func DefRefs(condition string) (ret []map[*Block]*Block) {
|
||||
func DefRefs(condition string, limit int) (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"
|
||||
if "" != condition {
|
||||
|
@ -453,7 +453,7 @@ func DefRefs(condition string) (ret []map[*Block]*Block) {
|
|||
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 {
|
||||
logging.LogErrorf("sql query failed: %s", err)
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue