Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-05-24 08:31:51 +08:00
commit 955651dc7e
4 changed files with 77 additions and 66 deletions

View file

@ -50,7 +50,6 @@
* [Does it support data synchronization through a third-party sync disk?](#does-it-support-data-synchronization-through-a-third-party-sync-disk)
* [Is SiYuan open source?](#is-siyuan-open-source)
* [How to upgrade to a new version?](#how-to-upgrade-to-a-new-version)
* [Is there any note for deleting docs?](#is-there-any-note-for-deleting-docs)
* [How can I just wrap and not start a new paragraph?](#how-can-i-just-wrap-and-not-start-a-new-paragraph)
* [What if some blocks (such as paragraph blocks in list items) cannot find the block icon?](#what-if-some-blocks-such-as-paragraph-blocks-in-list-items-cannot-find-the-block-icon)
* [How to share notes?](#how-to-share-notes)

View file

@ -50,7 +50,6 @@
* [支持通过第三方同步盘进行数据同步吗?](#支持通过第三方同步盘进行数据同步吗)
* [思源是开源的吗?](#思源是开源的吗)
* [如何升级到新版本?](#如何升级到新版本)
* [删除文档有什么注意事项吗?](#删除文档有什么注意事项吗)
* [如何才能只换行不新起段落?](#如何才能只换行不新起段落)
* [有的块(比如在列表项中的段落块)找不到块标怎么办?](#有的块比如在列表项中的段落块找不到块标怎么办)
* [如何分享笔记?](#如何分享笔记)

View file

@ -35,6 +35,7 @@ import (
"github.com/siyuan-note/logging"
"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"
"github.com/siyuan-note/siyuan/kernel/util"
@ -78,6 +79,8 @@ func DuplicateDatabaseBlock(avID string) (newAvID, newBlockID string, err error)
logging.LogErrorf("write attribute view [%s] failed: %s", newAvID, err)
return
}
updateBoundBlockAvsAttribute([]string{newAvID})
return
}
@ -3314,3 +3317,73 @@ func replaceRelationAvValues(avID, previousID, nextID string) {
}
}
}
func updateBoundBlockAvsAttribute(avIDs []string) {
// 更新指定 avIDs 中绑定块的 avs 属性
cachedTrees, saveTrees := map[string]*parse.Tree{}, map[string]*parse.Tree{}
luteEngine := util.NewLute()
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)
}
}

View file

@ -48,7 +48,6 @@ import (
"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"
@ -300,71 +299,12 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
av.BatchUpsertBlockRel(avNodes)
}
// 如果数据库中绑定的块不在导入的文档中
cachedTrees, saveTrees := map[string]*parse.Tree{}, map[string]*parse.Tree{}
// 如果数据库中绑定的块不在导入的文档中,则需要单独更新这些绑定块的属性
var attrViewIDs []string
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)
attrViewIDs = append(attrViewIDs, avID)
}
updateBoundBlockAvsAttribute(attrViewIDs)
}
// 将关联的闪卡数据合并到默认卡包 data/storage/riff/20230218211946-2kw8jgx 中