From 913b3fd2546850c4bc32c8703244404919907a53 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 15 Nov 2024 16:57:15 +0800 Subject: [PATCH] :art: Improve importing .sy.zip https://github.com/siyuan-note/siyuan/issues/13011 --- kernel/model/import.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/kernel/model/import.go b/kernel/model/import.go index 7c52b3d30..5c7cb8923 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -366,23 +366,17 @@ func ImportSY(zipPath, boxID, toPath string) (err error) { logging.LogErrorf("remove temp storage av dir failed: %s", removeErr) } - // 清理一些冗余的数据 - avDir := filepath.Join(util.DataDir, "storage", "av") - for _, tree := range trees { - ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { - if !entering { - return ast.WalkContinue - } - - ial := parse.IAL2Map(n.KramdownIAL) - avIDs := strings.Split(ial[av.NodeAttrNameAvs], ",") - for _, avID := range avIDs { - if !filelock.IsExist(filepath.Join(avDir, avID+".json")) { - n.RemoveIALAttr(av.NodeAttrNameAvs) + if 1 > len(avIDs) { // 如果本次没有导入数据库,则清理掉文档中的数据库属性 https://github.com/siyuan-note/siyuan/issues/13011 + for _, tree := range trees { + ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { + if !entering || !n.IsBlock() { + return ast.WalkContinue } - } - return ast.WalkContinue - }) + + n.RemoveIALAttr(av.NodeAttrNameAvs) + return ast.WalkContinue + }) + } } // 写回 .sy