Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: fix encrypted-notebook blocktree path prefix queries box routing #18034

Daniel66174b5e8538
diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go
index f53885a510..31258f8215 100644
--- a/kernel/model/flashcard.go
+++ b/kernel/model/flashcard.go
@@ -657,7 +657,7 @@ func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDsMap map[string]bool,
return
}
- bts := treenode.GetBlockTreesByPathPrefix(strings.TrimSuffix(root.Path, ".sy"))
+ bts := treenode.GetBlockTreesByPathPrefix(root.BoxID, strings.TrimSuffix(root.Path, ".sy"))
for _, bt := range bts {
treeBlockIDsMap[bt.ID] = true
treeBlockIDs = append(treeBlockIDs, bt.ID)
diff --git a/kernel/sql/queue.go b/kernel/sql/queue.go
index bb8d2db0ad..31979a01c7 100644
--- a/kernel/sql/queue.go
+++ b/kernel/sql/queue.go
@@ -156,7 +156,7 @@ func FlushQueue() {
}
}
if nil != renameTreeOp {
- childCount := treenode.CountBlockTreesByPathPrefix(path.Dir(renameTreeOp.indexTree.Path))
+ childCount := treenode.CountBlockTreesByPathPrefix(renameTreeOp.indexTree.Box, path.Dir(renameTreeOp.indexTree.Path))
if 512 < childCount {
scale := math.Log(float64(childCount)/512.0+1.0) / math.Log(2.0)
secs := 1.0 * scale
diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.go
index 41b639d464..c33c71e4b8 100644
--- a/kernel/treenode/blocktree.go
+++ b/kernel/treenode/blocktree.go
@@ -475,9 +475,9 @@ func RemoveBlockTreesByRootID(boxID, rootID string) {
}
}
-func CountBlockTreesByPathPrefix(pathPrefix string) (ret int) {
- sqlStmt := "SELECT COUNT(*) FROM blocktrees WHERE path LIKE ?"
- err := queryRow(sqlStmt, pathPrefix+"%").Scan(&ret)
+func CountBlockTreesByPathPrefix(boxID, pathPrefix string) (ret int) {
+ sqlStmt := "SELECT COUNT(*) FROM blocktrees WHERE path LIKE ? AND box_id = ?"
+ err := queryRowForBox(boxID, sqlStmt, pathPrefix+"%", boxID).Scan(&ret)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return 0
@@ -487,9 +487,9 @@ func CountBlockTreesByPathPrefix(pathPrefix string) (ret int) {
return
}
-func GetBlockTreesByPathPrefix(pathPrefix string) (ret []*BlockTree) {
- sqlStmt := "SELECT * FROM blocktrees WHERE path LIKE ?"
- rows, err := query(sqlStmt, pathPrefix+"%")
+func GetBlockTreesByPathPrefix(boxID, pathPrefix string) (ret []*BlockTree) {
+ sqlStmt := "SELECT * FROM blocktrees WHERE path LIKE ? AND box_id = ?"
+ rows, err := queryForBox(boxID, sqlStmt, pathPrefix+"%", boxID)
if err != nil {
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
return