Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Nov 22, 2024
2 parents 8a6ba2b + a486097 commit a5ea85f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kernel/model/backlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions kernel/model/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
Expand Down
6 changes: 4 additions & 2 deletions kernel/sql/block_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions kernel/sql/block_ref_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit a5ea85f

Please sign in to comment.