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

This commit is contained in:
Vanessa 2024-10-19 17:46:17 +08:00
commit 1a6c720bb5
3 changed files with 20 additions and 43 deletions

View file

@ -1449,38 +1449,17 @@ func (tx *Transaction) doRemoveAttrViewView(operation *Operation) (ret *TxErr) {
func getMirrorBlocksNodes(avID string) (trees []*parse.Tree, nodes []*ast.Node) {
mirrorBlockIDs := treenode.GetMirrorAttrViewBlockIDs(avID)
mirrorBlockTree := map[string]*parse.Tree{}
treeCache := map[string]*parse.Tree{}
for _, mirrorBlock := range mirrorBlockIDs {
bt := treenode.GetBlockTree(mirrorBlock)
if nil == bt {
logging.LogErrorf("get block tree by block ID [%s] failed", mirrorBlock)
continue
}
tree := mirrorBlockTree[mirrorBlock]
if nil == tree {
tree, _ = LoadTreeByBlockID(mirrorBlock)
if nil == tree {
logging.LogErrorf("load tree by block ID [%s] failed", mirrorBlock)
continue
}
treeCache[tree.ID] = tree
mirrorBlockTree[mirrorBlock] = tree
}
}
for _, mirrorBlockID := range mirrorBlockIDs {
tree := mirrorBlockTree[mirrorBlockID]
node := treenode.GetNodeInTree(tree, mirrorBlockID)
mirrorBlockTrees := filesys.LoadTrees(mirrorBlockIDs)
for id, tree := range mirrorBlockTrees {
node := treenode.GetNodeInTree(tree, id)
if nil == node {
logging.LogErrorf("get node in tree by block ID [%s] failed", mirrorBlockID)
logging.LogErrorf("get node in tree by block ID [%s] failed", id)
continue
}
nodes = append(nodes, node)
}
for _, tree := range treeCache {
for _, tree := range mirrorBlockTrees {
trees = append(trees, tree)
}
return

View file

@ -30,6 +30,7 @@ import (
"github.com/88250/lute/parse"
"github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
@ -82,32 +83,27 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren bool) (
linkRefs, _, excludeBacklinkIDs := buildLinkRefs(rootID, refs, keyword)
tmpMentions, mentionKeywords := buildTreeBackmention(sqlBlock, linkRefs, keyword, excludeBacklinkIDs, beforeLen)
luteEngine := NewLute()
treeCache := map[string]*parse.Tree{}
luteEngine := util.NewLute()
var mentions []*Block
for _, mention := range tmpMentions {
if mention.RootID == refTreeID {
mentions = append(mentions, mention)
}
}
var mentionBlockIDs []string
for _, mention := range mentions {
mentionBlockIDs = append(mentionBlockIDs, mention.ID)
}
mentionBlockIDs = gulu.Str.RemoveDuplicatedElem(mentionBlockIDs)
if "" != keyword {
mentionKeywords = append(mentionKeywords, keyword)
}
mentionKeywords = gulu.Str.RemoveDuplicatedElem(mentionKeywords)
for _, mention := range mentions {
refTree := treeCache[mention.RootID]
if nil == refTree {
var loadErr error
refTree, loadErr = LoadTreeByBlockID(mention.ID)
if nil != loadErr {
logging.LogWarnf("load ref tree [%s] failed: %s", mention.ID, loadErr)
continue
}
treeCache[mention.RootID] = refTree
}
backlink := buildBacklink(mention.ID, refTree, mentionKeywords, luteEngine)
trees := filesys.LoadTrees(mentionBlockIDs)
for id, tree := range trees {
backlink := buildBacklink(id, tree, mentionKeywords, luteEngine)
ret = append(ret, backlink)
}
return
@ -138,7 +134,7 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren bool) (ret
return
}
luteEngine := NewLute()
luteEngine := util.NewLute()
for _, linkRef := range linkRefs {
var keywords []string
if "" != keyword {

View file

@ -325,11 +325,13 @@ func TransferBlockRef(fromID, toID string, refIDs []string) (err error) {
if 1 > len(refIDs) { // 如果不指定 refIDs则转移所有引用了 fromID 的块
refIDs, _ = sql.QueryRefIDsByDefID(fromID, false)
}
for _, refID := range refIDs {
tree, _ := LoadTreeByBlockID(refID)
trees := filesys.LoadTrees(refIDs)
for refID, tree := range trees {
if nil == tree {
continue
}
node := treenode.GetNodeInTree(tree, refID)
textMarks := node.ChildrenByType(ast.NodeTextMark)
for _, textMark := range textMarks {