From f9a696aa140b4310dc96da2a9cbe0871142b3ffc Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 25 Oct 2024 22:18:50 +0800 Subject: [PATCH 1/2] :art: Clean code --- kernel/model/search.go | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/model/search.go b/kernel/model/search.go index 77ba2c45fa0..417598b351e 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -1430,7 +1430,6 @@ func fullTextSearchByFTSWithRoot(query, boxFilter, pathFilter, typeFilter, ignor for j, block := range blocks { if resultBlock.ID == block.ID { resultBlocks[i] = block - // 减少 blocks blocks = append(blocks[:j], blocks[j+1:]...) break } From 1f011dc06c63f410acc46480acf8efde9391b50b Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 25 Oct 2024 22:39:24 +0800 Subject: [PATCH 2/2] :art: Improve database assets calc https://github.com/siyuan-note/siyuan/issues/12880 --- kernel/model/assets.go | 80 +++++++++++++++++++----------------------- kernel/model/export.go | 2 -- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index df7b8aaa863..dc6ae71f55f 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -362,8 +362,6 @@ func UploadAssets2Cloud(rootID string) (count int, err error) { assets := assetsLinkDestsInTree(tree) embedAssets := assetsLinkDestsInQueryEmbedNodes(tree) assets = append(assets, embedAssets...) - avAssets := assetsLinkDestsInAttributeViewNodes(tree) - assets = append(assets, avAssets...) assets = gulu.Str.RemoveDuplicatedElem(assets) count, err = uploadAssets2Cloud(assets, bizTypeUploadAssets) if err != nil { @@ -913,46 +911,6 @@ func emojisInTree(tree *parse.Tree) (ret []string) { return } -func assetsLinkDestsInAttributeViewNodes(tree *parse.Tree) (ret []string) { - // The images in the databases are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/11948 - - ret = []string{} - ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { - if !entering || ast.NodeAttributeView != n.Type { - return ast.WalkContinue - } - - attrView, _ := av.ParseAttributeView(n.AttributeViewID) - if nil == attrView { - return ast.WalkContinue - } - - for _, keyValues := range attrView.KeyValues { - if av.KeyTypeMAsset != keyValues.Key.Type { - continue - } - - for _, value := range keyValues.Values { - if 1 > len(value.MAsset) { - continue - } - - for _, asset := range value.MAsset { - dest := asset.Content - if !treenode.IsRelativePath([]byte(dest)) { - continue - } - - ret = append(ret, strings.TrimSpace(dest)) - } - } - } - return ast.WalkContinue - }) - ret = gulu.Str.RemoveDuplicatedElem(ret) - return -} - func assetsLinkDestsInQueryEmbedNodes(tree *parse.Tree) (ret []string) { // The images in the embed blocks are not uploaded to the community hosting https://github.com/siyuan-note/siyuan/issues/10042 @@ -1010,7 +968,7 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) { // 修改以下代码时需要同时修改 database 构造行级元素实现,增加必要的类型 if !entering || (ast.NodeLinkDest != n.Type && ast.NodeHTMLBlock != n.Type && ast.NodeInlineHTML != n.Type && ast.NodeIFrame != n.Type && ast.NodeWidget != n.Type && ast.NodeAudio != n.Type && ast.NodeVideo != n.Type && - !n.IsTextMarkType("a") && !n.IsTextMarkType("file-annotation-ref")) { + ast.NodeAttributeView != n.Type && !n.IsTextMarkType("a") && !n.IsTextMarkType("file-annotation-ref")) { return ast.WalkContinue } @@ -1040,6 +998,42 @@ func assetsLinkDestsInNode(node *ast.Node) (ret []string) { dest := n.TextMarkFileAnnotationRefID[:strings.LastIndexByte(n.TextMarkFileAnnotationRefID, '/')] dest = strings.TrimSpace(dest) ret = append(ret, dest) + } else if ast.NodeAttributeView == n.Type { + attrView, _ := av.ParseAttributeView(n.AttributeViewID) + if nil == attrView { + return ast.WalkContinue + } + + for _, keyValues := range attrView.KeyValues { + if av.KeyTypeMAsset == keyValues.Key.Type { + for _, value := range keyValues.Values { + if 1 > len(value.MAsset) { + continue + } + + for _, asset := range value.MAsset { + dest := asset.Content + if !treenode.IsRelativePath([]byte(dest)) { + continue + } + + ret = append(ret, strings.TrimSpace(dest)) + } + } + } else if av.KeyTypeURL == keyValues.Key.Type { + for _, value := range keyValues.Values { + if nil != value.URL { + dest := value.URL.Content + if !treenode.IsRelativePath([]byte(dest)) { + continue + } + + ret = append(ret, strings.TrimSpace(dest)) + } + } + } + + } } else { if ast.NodeWidget == n.Type { dataAssets := n.IALAttr("custom-data-assets") diff --git a/kernel/model/export.go b/kernel/model/export.go index a73b0c6d0b7..f9e7f57f7b2 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -218,8 +218,6 @@ func Export2Liandi(id string) (err error) { assets := assetsLinkDestsInTree(tree) embedAssets := assetsLinkDestsInQueryEmbedNodes(tree) assets = append(assets, embedAssets...) - avAssets := assetsLinkDestsInAttributeViewNodes(tree) - assets = append(assets, avAssets...) assets = gulu.Str.RemoveDuplicatedElem(assets) _, err = uploadAssets2Cloud(assets, bizTypeExport2Liandi) if err != nil {