An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/17534 https://github.com/siyuan-note/siyuan/issues/17545
Daniel1486804d67c2
diff --git a/kernel/model/box.go b/kernel/model/box.goindex 7d9a694bed..aa119de6ae 100644--- a/kernel/model/box.go+++ b/kernel/model/box.go@@ -466,24 +466,10 @@ func isSkipFile(filename string) bool {func moveTree(tree *parse.Tree) {treenode.SetBlockTreePath(tree)-- if hidden := tree.Root.IALAttr("custom-hidden"); "true" == hidden {- tree.Root.RemoveIALAttr("custom-hidden")- filesys.WriteTree(tree)- }-- sql.RemoveTreeQueue(tree.ID)- sql.IndexTreeQueue(tree)+ sql.MoveTreeQueue(tree)box := Conf.Box(tree.Box)- box.renameSubTrees(tree)-- refreshDocInfo(tree)-}--func (box *Box) renameSubTrees(tree *parse.Tree) {subFiles := box.ListFiles(tree.Path)-luteEngine := util.NewLute()for _, subFile := range subFiles {if !strings.HasSuffix(subFile.path, ".sy") {@@ -496,10 +482,12 @@ func (box *Box) renameSubTrees(tree *parse.Tree) {}treenode.SetBlockTreePath(subTree)- sql.RenameSubTreeQueue(subTree)+ sql.MoveTreeQueue(subTree)msg := fmt.Sprintf(Conf.Language(107), html.EscapeString(subTree.HPath))util.PushStatusBar(msg)}++ refreshDocInfo(tree)}func parseKTree(kramdown []byte) (ret *parse.Tree) {diff --git a/kernel/model/file.go b/kernel/model/file.goindex d05a9b0ac7..e4b7612264 100644--- a/kernel/model/file.go+++ b/kernel/model/file.go@@ -1717,7 +1717,6 @@ func RenameDoc(boxID, p, title string) (err error) {util.PushEvent(evt)}if titleChanged {- box.renameSubTrees(tree)updateRefTextRenameDoc(tree)}if titleChanged || emptyAttrUpdated {diff --git a/kernel/sql/database.go b/kernel/sql/database.goindex 7c5071b74b..52628162f2 100644--- a/kernel/sql/database.go+++ b/kernel/sql/database.go@@ -1261,6 +1261,32 @@ func batchUpdatePath(tx *sql.Tx, tree *parse.Tree, context map[string]any) (errreturn}}++ stmt = "UPDATE spans SET box = ?, path = ? WHERE root_id = ?"+ if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.ID); err != nil {+ return+ }+ stmt = "UPDATE assets SET box = ?, docpath = ? WHERE root_id = ?"+ if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.ID); err != nil {+ return+ }+ stmt = "UPDATE refs SET box = ?, path = ? WHERE root_id = ?"+ if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.ID); err != nil {+ return+ }+ stmt = "UPDATE refs SET def_block_path = ? WHERE def_block_root_id = ?"+ if err = execStmtTx(tx, stmt, tree.Path, tree.ID); err != nil {+ return+ }+ stmt = "UPDATE file_annotation_refs SET box = ?, path = ? WHERE root_id = ?"+ if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.ID); err != nil {+ return+ }+ stmt = "UPDATE attributes SET box = ?, path = ? WHERE root_id = ?"+ if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.ID); err != nil {+ return+ }+ClearCache()evtHash := fmt.Sprintf("%x", sha256.Sum256([]byte(tree.ID)))[:7]eventbus.Publish(eventbus.EvtSQLUpdateBlocksHPaths, context, 1, evtHash)diff --git a/kernel/sql/queue.go b/kernel/sql/queue.goindex 112433976d..b68f1b7ac1 100644--- a/kernel/sql/queue.go+++ b/kernel/sql/queue.go@@ -44,14 +44,13 @@ var (type dbQueueOperation struct {inQueueTime time.Time- action string // upsert/delete/delete_id/rename/rename_sub_tree/delete_box/delete_box_refs/index/delete_ids/update_block_content/delete_assets- indexTree *parse.Tree // index+ action string // upsert/delete/delete_id/rename/move/delete_box/delete_box_refs/index/delete_ids/update_block_content/delete_assets+ indexTree *parse.Tree // index/rename/moveupsertTree *parse.Tree // upsert/update_refs/delete_refsremoveTreeBox, removeTreePath string // deleteremoveTreeID string // delete_idremoveTreeIDs []string // delete_idsbox string // delete_box/delete_box_refs/index- renameTree *parse.Tree // rename/rename_sub_treeblock *Block // update_block_contentid string // index_noderemoveAssetHashes []string // delete_assets@@ -133,7 +132,7 @@ func FlushQueue() {}}if nil != renameSubTreeOp {- childCount := treenode.CountBlockTreesByPathPrefix(path.Dir(renameSubTreeOp.renameTree.Path))+ childCount := treenode.CountBlockTreesByPathPrefix(path.Dir(renameSubTreeOp.indexTree.Path))if 512 < childCount {scale := math.Log(float64(childCount)/512.0+1.0) / math.Log(2.0)secs := 1.0 * scale@@ -143,7 +142,7 @@ func FlushQueue() {if secs > 12.0 {secs = 12.0}- logging.LogInfof("rename sub tree [%s] with large child count [%d], sleep [%.2fs] to wait for more operations", renameSubTreeOp.renameTree.Path, childCount, secs)+ logging.LogInfof("rename sub tree [%s] with large child count [%d], sleep [%.2fs] to wait for more operations", renameSubTreeOp.indexTree.Path, childCount, secs)time.Sleep(time.Duration(secs * float64(time.Second)))}}@@ -218,14 +217,14 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]any) (err errorcase "delete_ids":err = batchDeleteByRootIDs(tx, op.removeTreeIDs, context)case "rename":- err = batchUpdateHPath(tx, op.renameTree, context)+ err = batchUpdateHPath(tx, op.indexTree, context)if err != nil {break}- err = updateRootContent(tx, path.Base(op.renameTree.HPath), op.renameTree.Root.IALAttr("updated"), treenode.IALStr(op.renameTree.Root), op.renameTree.ID)- case "rename_sub_tree":- err = batchUpdatePath(tx, op.renameTree, context)+ err = updateRootContent(tx, path.Base(op.indexTree.HPath), op.indexTree.Root.IALAttr("updated"), treenode.IALStr(op.indexTree.Root), op.indexTree.ID)+ case "move":+ err = batchUpdatePath(tx, op.indexTree, context)case "delete_box":err = deleteByBoxTx(tx, op.box)case "delete_box_refs":@@ -377,12 +376,12 @@ func RenameTreeQueue(tree *parse.Tree) {defer dbQueueLock.Unlock()newOp := &dbQueueOperation{- renameTree: tree,+ indexTree: tree,inQueueTime: time.Now(),action: "rename",}for i, op := range operationQueue {- if "rename" == op.action && op.renameTree.ID == tree.ID { // 相同树则覆盖+ if "rename" == op.action && op.indexTree.ID == tree.ID { // 相同树则覆盖operationQueue[i] = newOpreturn}@@ -390,17 +389,17 @@ func RenameTreeQueue(tree *parse.Tree) {appendOperation(newOp)}-func RenameSubTreeQueue(tree *parse.Tree) {+func MoveTreeQueue(tree *parse.Tree) {dbQueueLock.Lock()defer dbQueueLock.Unlock()newOp := &dbQueueOperation{- renameTree: tree,+ indexTree: tree,inQueueTime: time.Now(),- action: "rename_sub_tree",+ action: "move",}for i, op := range operationQueue {- if "rename_sub_tree" == op.action && op.renameTree.ID == tree.ID { // 相同树则覆盖+ if "move" == op.action && op.indexTree.ID == tree.ID { // 相同树则覆盖operationQueue[i] = newOpreturn}