This commit is contained in:
Daniel 2024-11-22 23:27:38 +08:00
parent 83b932478e
commit a48609755e
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 10 additions and 8 deletions

View file

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

View file

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