mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve Add to Database https://github.com/siyuan-note/siyuan/issues/10659
This commit is contained in:
parent
6270d55fa3
commit
c7c7bdb950
2 changed files with 58 additions and 120 deletions
|
|
@ -1174,6 +1174,7 @@ type AvSearchResult struct {
|
||||||
AvID string `json:"avID"`
|
AvID string `json:"avID"`
|
||||||
AvName string `json:"avName"`
|
AvName string `json:"avName"`
|
||||||
ViewName string `json:"viewName"`
|
ViewName string `json:"viewName"`
|
||||||
|
ViewID string `json:"viewID"`
|
||||||
BlockID string `json:"blockID"`
|
BlockID string `json:"blockID"`
|
||||||
HPath string `json:"hPath"`
|
HPath string `json:"hPath"`
|
||||||
Children []*AvSearchResult `json:"children,omitempty"`
|
Children []*AvSearchResult `json:"children,omitempty"`
|
||||||
|
|
@ -1264,96 +1265,80 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch
|
||||||
avIDs = append(avIDs, a.AvID)
|
avIDs = append(avIDs, a.AvID)
|
||||||
}
|
}
|
||||||
|
|
||||||
avBlocks := treenode.BatchGetMirrorAttrViewBlocks(avIDs)
|
|
||||||
var blockIDs []string
|
var blockIDs []string
|
||||||
for _, avBlock := range avBlocks {
|
for _, bIDs := range avBlockRels {
|
||||||
blockIDs = append(blockIDs, avBlock.BlockIDs...)
|
blockIDs = append(blockIDs, bIDs...)
|
||||||
}
|
}
|
||||||
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)
|
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)
|
||||||
|
|
||||||
trees := filesys.LoadTrees(blockIDs)
|
trees := filesys.LoadTrees(blockIDs)
|
||||||
for _, avBlock := range avBlocks {
|
hitAttrViews := map[string]bool{}
|
||||||
if 1 > len(avBlock.BlockIDs) {
|
for _, blockID := range blockIDs {
|
||||||
|
tree := trees[blockID]
|
||||||
|
if nil == tree {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
parentResult := buildSearchAttributeViewResult(avSearchTmpResults, avBlock.BlockIDs[0], trees, excludeAvIDs)
|
node := treenode.GetNodeInTree(tree, blockID)
|
||||||
if nil == parentResult {
|
if nil == node || "" == node.AttributeViewID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret = append(ret, parentResult)
|
|
||||||
for _, blockID := range avBlock.BlockIDs {
|
avID := node.AttributeViewID
|
||||||
result := buildSearchAttributeViewResult(avSearchTmpResults, blockID, trees, excludeAvIDs)
|
var existAv *AvSearchTempResult
|
||||||
if nil != result {
|
for _, tmpResult := range avSearchTmpResults {
|
||||||
parentResult.Children = append(parentResult.Children, result)
|
if tmpResult.AvID == avID {
|
||||||
|
existAv = tmpResult
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if nil == existAv || gulu.Str.Contains(avID, excludeAvIDs) {
|
||||||
return
|
continue
|
||||||
}
|
|
||||||
|
|
||||||
func buildSearchAttributeViewResult(avSearchTempResults []*AvSearchTempResult, blockID string, trees map[string]*parse.Tree, excludeAvIDs []string) (ret *AvSearchResult) {
|
|
||||||
tree := trees[blockID]
|
|
||||||
if nil == tree {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
node := treenode.GetNodeInTree(tree, blockID)
|
|
||||||
if nil == node {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if "" == node.AttributeViewID {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
avID := node.AttributeViewID
|
|
||||||
var existAv *AvSearchTempResult
|
|
||||||
for _, tmpResult := range avSearchTempResults {
|
|
||||||
if tmpResult.AvID == avID {
|
|
||||||
existAv = tmpResult
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if nil == existAv {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
attrView, _ := av.ParseAttributeView(avID)
|
if hitAttrViews[avID] {
|
||||||
if nil == attrView {
|
continue
|
||||||
return
|
}
|
||||||
}
|
hitAttrViews[avID] = true
|
||||||
viewID := node.IALAttr(av.NodeAttrView)
|
|
||||||
if "" == viewID {
|
|
||||||
viewID = attrView.ViewID
|
|
||||||
}
|
|
||||||
view, _ := attrView.GetCurrentView(viewID)
|
|
||||||
if nil == view {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var hPath string
|
attrView, _ := av.ParseAttributeView(avID)
|
||||||
baseBlock := treenode.GetBlockTreeRootByPath(node.Box, node.Path)
|
if nil == attrView {
|
||||||
if nil != baseBlock {
|
continue
|
||||||
hPath = baseBlock.HPath
|
}
|
||||||
}
|
|
||||||
box := Conf.Box(node.Box)
|
|
||||||
if nil != box {
|
|
||||||
hPath = box.Name + hPath
|
|
||||||
}
|
|
||||||
|
|
||||||
name := existAv.AvName
|
var hPath string
|
||||||
if "" == name {
|
baseBlock := treenode.GetBlockTreeRootByPath(node.Box, node.Path)
|
||||||
name = Conf.language(267)
|
if nil != baseBlock {
|
||||||
}
|
hPath = baseBlock.HPath
|
||||||
|
}
|
||||||
|
box := Conf.Box(node.Box)
|
||||||
|
if nil != box {
|
||||||
|
hPath = box.Name + hPath
|
||||||
|
}
|
||||||
|
|
||||||
if !gulu.Str.Contains(avID, excludeAvIDs) {
|
name := existAv.AvName
|
||||||
ret = &AvSearchResult{
|
if "" == name {
|
||||||
AvID: avID,
|
name = Conf.language(267)
|
||||||
AvName: existAv.AvName,
|
}
|
||||||
ViewName: view.Name,
|
|
||||||
BlockID: blockID,
|
parent := &AvSearchResult{
|
||||||
HPath: hPath,
|
AvID: avID,
|
||||||
|
AvName: existAv.AvName,
|
||||||
|
BlockID: blockID,
|
||||||
|
HPath: hPath,
|
||||||
|
}
|
||||||
|
ret = append(ret, parent)
|
||||||
|
|
||||||
|
for _, view := range attrView.Views {
|
||||||
|
child := &AvSearchResult{
|
||||||
|
AvID: avID,
|
||||||
|
AvName: existAv.AvName,
|
||||||
|
ViewName: view.Name,
|
||||||
|
ViewID: view.ID,
|
||||||
|
BlockID: blockID,
|
||||||
|
HPath: hPath,
|
||||||
|
}
|
||||||
|
parent.Children = append(parent.Children, child)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -55,50 +55,3 @@ func GetMirrorAttrViewBlockIDs(avID string) (ret []string) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type AvBlock struct {
|
|
||||||
AvID string
|
|
||||||
BlockIDs []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func BatchGetMirrorAttrViewBlocks(avIDs []string) (ret []*AvBlock) {
|
|
||||||
av.AttributeViewBlocksLock.Lock()
|
|
||||||
defer av.AttributeViewBlocksLock.Unlock()
|
|
||||||
|
|
||||||
ret = []*AvBlock{}
|
|
||||||
|
|
||||||
blocks := filepath.Join(util.DataDir, "storage", "av", "blocks.msgpack")
|
|
||||||
if !filelock.IsExist(blocks) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := filelock.ReadFile(blocks)
|
|
||||||
if err != nil {
|
|
||||||
logging.LogErrorf("read attribute view blocks failed: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
avBlocks := map[string][]string{}
|
|
||||||
if err = msgpack.Unmarshal(data, &avBlocks); err != nil {
|
|
||||||
logging.LogErrorf("unmarshal attribute view blocks failed: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, avID := range avIDs {
|
|
||||||
var blockIDs []string
|
|
||||||
bts := GetBlockTrees(avBlocks[avID])
|
|
||||||
for blockID := range bts {
|
|
||||||
blockIDs = append(blockIDs, blockID)
|
|
||||||
}
|
|
||||||
if 1 > len(blockIDs) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
avBlock := &AvBlock{
|
|
||||||
AvID: avID,
|
|
||||||
BlockIDs: blockIDs,
|
|
||||||
}
|
|
||||||
ret = append(ret, avBlock)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue