From 2a47791b4d9c5e328c94386a67e86c0cc9966558 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 16 Jun 2024 11:08:21 +0800 Subject: [PATCH] :art: Improve duplicating for a doc with databases https://github.com/siyuan-note/siyuan/issues/11602 --- kernel/model/file.go | 12 +++++++++--- kernel/model/tree.go | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index ffb20a41a..e4e3fc4e3 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1640,13 +1640,19 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) { } indexHistoryDir(filepath.Base(historyDir), util.NewLute()) - // 刷新文档关联的数据库 https://github.com/siyuan-note/siyuan/issues/11731 allRemoveRootIDs := []string{tree.ID} allRemoveRootIDs = append(allRemoveRootIDs, removeIDs...) for _, rootID := range allRemoveRootIDs { - if removeTree, _ := LoadTreeByBlockID(rootID); nil != removeTree { - syncDelete2AttributeView(removeTree.Root) + removeTree, _ := LoadTreeByBlockID(rootID) + if nil == removeTree { + continue } + + // 刷新文档关联的数据库 https://github.com/siyuan-note/siyuan/issues/11731 + syncDelete2AttributeView(removeTree.Root) + + // 解绑数据库关联 + removeAvBlockRel(removeTree.Root) } if existChildren { diff --git a/kernel/model/tree.go b/kernel/model/tree.go index 7e6c97a81..7fef7c186 100644 --- a/kernel/model/tree.go +++ b/kernel/model/tree.go @@ -30,6 +30,7 @@ import ( "github.com/88250/lute/parse" "github.com/siyuan-note/filelock" "github.com/siyuan-note/logging" + "github.com/siyuan-note/siyuan/kernel/av" "github.com/siyuan-note/siyuan/kernel/filesys" "github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/task" @@ -105,6 +106,23 @@ func resetTree(tree *parse.Tree, titleSuffix string) { } return ast.WalkContinue }) + + var attrViewIDs []string + // 绑定镜像数据库 + ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { + if !entering { + return ast.WalkContinue + } + + if ast.NodeAttributeView == n.Type { + av.UpsertBlockRel(n.AttributeViewID, n.ID) + attrViewIDs = append(attrViewIDs, n.AttributeViewID) + } + return ast.WalkContinue + }) + + // 清空文档绑定的数据库 + tree.Root.RemoveIALAttr(av.NodeAttrNameAvs) } func pagedPaths(localPath string, pageSize int) (ret map[int][]string) {