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: Improve av importing https://github.com/siyuan-note/siyuan/issues/11460
Daniel5d637f228750
diff --git a/kernel/model/import.go b/kernel/model/import.goindex d97d189c71..3c933a77e2 100644--- a/kernel/model/import.go+++ b/kernel/model/import.go@@ -22,8 +22,6 @@ import ("encoding/json""errors""fmt"- "github.com/siyuan-note/riff"- "github.com/siyuan-note/siyuan/kernel/av""image""image/jpeg""image/png"@@ -48,6 +46,9 @@ import ("github.com/88250/lute/render""github.com/siyuan-note/filelock""github.com/siyuan-note/logging"+ "github.com/siyuan-note/riff"+ "github.com/siyuan-note/siyuan/kernel/av"+ "github.com/siyuan-note/siyuan/kernel/cache""github.com/siyuan-note/siyuan/kernel/filesys""github.com/siyuan-note/siyuan/kernel/sql""github.com/siyuan-note/siyuan/kernel/treenode"@@ -289,6 +290,72 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {avNodes := tree.Root.ChildrenByType(ast.NodeAttributeView)av.BatchUpsertBlockRel(avNodes)}++ // 如果数据库中绑定的块不在导入的文档中+ cachedTrees, saveTrees := map[string]*parse.Tree{}, map[string]*parse.Tree{}+ for _, avID := range avIDs {+ attrView, _ := av.ParseAttributeView(avID)+ if nil == attrView {+ continue+ }++ blockKeyValues := attrView.GetBlockKeyValues()+ for _, blockValue := range blockKeyValues.Values {+ if blockValue.IsDetached {+ continue+ }+ bt := treenode.GetBlockTree(blockValue.BlockID)+ if nil == bt {+ continue+ }++ tree := cachedTrees[bt.RootID]+ if nil == tree {+ tree, _ = filesys.LoadTree(bt.BoxID, bt.Path, luteEngine)+ if nil == tree {+ continue+ }+ cachedTrees[bt.RootID] = tree+ }++ node := treenode.GetNodeInTree(tree, blockValue.BlockID)+ if nil == node {+ continue+ }++ attrs := parse.IAL2Map(node.KramdownIAL)+ if "" == attrs[av.NodeAttrNameAvs] {+ attrs[av.NodeAttrNameAvs] = avID+ } else {+ nodeAvIDs := strings.Split(attrs[av.NodeAttrNameAvs], ",")+ nodeAvIDs = append(nodeAvIDs, avID)+ nodeAvIDs = gulu.Str.RemoveDuplicatedElem(nodeAvIDs)+ attrs[av.NodeAttrNameAvs] = strings.Join(nodeAvIDs, ",")+ saveTrees[bt.RootID] = tree+ }++ avNames := getAvNames(attrs[av.NodeAttrNameAvs])+ if "" != avNames {+ attrs[av.NodeAttrViewNames] = avNames+ }++ oldAttrs, setErr := setNodeAttrs0(node, attrs)+ if nil != setErr {+ continue+ }+ cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))+ pushBroadcastAttrTransactions(oldAttrs, node)+ }+ }++ for _, saveTree := range saveTrees {+ if treeErr := indexWriteTreeUpsertQueue(saveTree); nil != treeErr {+ logging.LogErrorf("index write tree upsert queue failed: %s", treeErr)+ }++ avNodes := saveTree.Root.ChildrenByType(ast.NodeAttributeView)+ av.BatchUpsertBlockRel(avNodes)+ }}// 将关联的闪卡数据合并到默认卡包 data/storage/riff/20230218211946-2kw8jgx 中