An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Improve performance of exporting .sy.zip for notebook https://github.com/siyuan-note/siyuan/issues/12653
Daniele70a0506cfcb
diff --git a/kernel/model/export.go b/kernel/model/export.goindex 0ea99c4a1b..a71565fb15 100644--- a/kernel/model/export.go+++ b/kernel/model/export.go@@ -1540,6 +1540,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (trees := map[string]*parse.Tree{}refTrees := map[string]*parse.Tree{}+ treeCache := map[string]*parse.Tree{}for i, p := range docPaths {docIAL := box.docIAL(p)if nil == docIAL {@@ -1556,7 +1557,8 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (}trees[tree.ID] = tree- refs := exportRefTrees(tree, trees)+ refs := map[string]*parse.Tree{}+ exportRefTrees(tree, &refs, &treeCache)for refTreeID, refTree := range refs {if nil == trees[refTreeID] {refTrees[refTreeID] = refTree@@ -2733,13 +2735,7 @@ type refAsFootnotes struct {refAnchorText string}-func exportRefTrees(tree *parse.Tree, treeCache map[string]*parse.Tree) (ret map[string]*parse.Tree) {- ret = map[string]*parse.Tree{}- exportRefTrees0(tree, &ret, treeCache)- return-}--func exportRefTrees0(tree *parse.Tree, retTrees *map[string]*parse.Tree, treeCache map[string]*parse.Tree) {+func exportRefTrees(tree *parse.Tree, retTrees *map[string]*parse.Tree, treeCache *map[string]*parse.Tree) {if nil != (*retTrees)[tree.ID] {return}@@ -2762,17 +2758,17 @@ func exportRefTrees0(tree *parse.Tree, retTrees *map[string]*parse.Tree, treeCacvar defTree *parse.Treevar err error- if treeCache[defBlock.RootID] != nil {- defTree = treeCache[defBlock.RootID]+ if (*treeCache)[defBlock.RootID] != nil {+ defTree = (*treeCache)[defBlock.RootID]} else {defTree, err = LoadTreeByBlockID(defBlock.RootID)if err != nil {return ast.WalkSkipChildren}- treeCache[defBlock.RootID] = defTree+ (*treeCache)[defBlock.RootID] = defTree}- exportRefTrees0(defTree, retTrees, treeCache)+ exportRefTrees(defTree, retTrees, treeCache)} else if ast.NodeAttributeView == n.Type {// 导出数据库所在文档时一并导出绑定块所在文档// Export the binding block docs when exporting the doc where the database is located https://github.com/siyuan-note/siyuan/issues/11486@@ -2800,17 +2796,17 @@ func exportRefTrees0(tree *parse.Tree, retTrees *map[string]*parse.Tree, treeCacvar defTree *parse.Treevar err error- if treeCache[defBlock.RootID] != nil {- defTree = treeCache[defBlock.RootID]+ if (*treeCache)[defBlock.RootID] != nil {+ defTree = (*treeCache)[defBlock.RootID]} else {defTree, err = LoadTreeByBlockID(defBlock.RootID)if err != nil {continue}- treeCache[defBlock.RootID] = defTree+ (*treeCache)[defBlock.RootID] = defTree}- exportRefTrees0(defTree, retTrees, treeCache)+ exportRefTrees(defTree, retTrees, treeCache)}}return ast.WalkContinue