This commit is contained in:
Daniel 2025-08-21 12:01:12 +08:00
parent 6270d55fa3
commit c7c7bdb950
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 58 additions and 120 deletions

View file

@ -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,72 +1265,45 @@ 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 {
continue
}
parentResult := buildSearchAttributeViewResult(avSearchTmpResults, avBlock.BlockIDs[0], trees, excludeAvIDs)
if nil == parentResult {
continue
}
ret = append(ret, parentResult)
for _, blockID := range avBlock.BlockIDs {
result := buildSearchAttributeViewResult(avSearchTmpResults, blockID, trees, excludeAvIDs)
if nil != result {
parentResult.Children = append(parentResult.Children, result)
}
}
}
return
}
func buildSearchAttributeViewResult(avSearchTempResults []*AvSearchTempResult, blockID string, trees map[string]*parse.Tree, excludeAvIDs []string) (ret *AvSearchResult) {
tree := trees[blockID] tree := trees[blockID]
if nil == tree { if nil == tree {
return continue
} }
node := treenode.GetNodeInTree(tree, blockID) node := treenode.GetNodeInTree(tree, blockID)
if nil == node { if nil == node || "" == node.AttributeViewID {
return continue
}
if "" == node.AttributeViewID {
return
} }
avID := node.AttributeViewID avID := node.AttributeViewID
var existAv *AvSearchTempResult var existAv *AvSearchTempResult
for _, tmpResult := range avSearchTempResults { for _, tmpResult := range avSearchTmpResults {
if tmpResult.AvID == avID { if tmpResult.AvID == avID {
existAv = tmpResult existAv = tmpResult
break break
} }
} }
if nil == existAv { if nil == existAv || gulu.Str.Contains(avID, excludeAvIDs) {
return continue
} }
if hitAttrViews[avID] {
continue
}
hitAttrViews[avID] = true
attrView, _ := av.ParseAttributeView(avID) attrView, _ := av.ParseAttributeView(avID)
if nil == attrView { if nil == attrView {
return continue
}
viewID := node.IALAttr(av.NodeAttrView)
if "" == viewID {
viewID = attrView.ViewID
}
view, _ := attrView.GetCurrentView(viewID)
if nil == view {
return
} }
var hPath string var hPath string
@ -1347,14 +1321,25 @@ func buildSearchAttributeViewResult(avSearchTempResults []*AvSearchTempResult, b
name = Conf.language(267) name = Conf.language(267)
} }
if !gulu.Str.Contains(avID, excludeAvIDs) { parent := &AvSearchResult{
ret = &AvSearchResult{ AvID: avID,
AvName: existAv.AvName,
BlockID: blockID,
HPath: hPath,
}
ret = append(ret, parent)
for _, view := range attrView.Views {
child := &AvSearchResult{
AvID: avID, AvID: avID,
AvName: existAv.AvName, AvName: existAv.AvName,
ViewName: view.Name, ViewName: view.Name,
ViewID: view.ID,
BlockID: blockID, BlockID: blockID,
HPath: hPath, HPath: hPath,
} }
parent.Children = append(parent.Children, child)
}
} }
return return
} }

View file

@ -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
}