feat(search): Optimized search result filtering and paging logic (#9287)

- Introduced the `filteredNodes` list to optimize the node filtering process
- Filtered results based on the page limit during paging
- Modified search logic to ensure nodes are within the user's base path
- Added access permission checks for node metadata
- Adjusted paging logic to avoid redundant node retrieval
pull/8608/merge
千石 2025-08-25 19:46:24 +08:00 committed by GitHub
parent d7723c378f
commit 3319f6ea6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 16 deletions

View File

@ -43,12 +43,18 @@ func Search(c *gin.Context) {
common.ErrorResp(c, err, 400)
return
}
nodes, total, err := search.Search(c, req.SearchReq)
var (
filteredNodes []model.SearchNode
)
for len(filteredNodes) < req.PerPage {
nodes, _, err := search.Search(c, req.SearchReq)
if err != nil {
common.ErrorResp(c, err, 500)
return
}
var filteredNodes []model.SearchNode
if len(nodes) == 0 {
break
}
for _, node := range nodes {
if !strings.HasPrefix(node.Parent, user.BasePath) {
continue
@ -61,10 +67,15 @@ func Search(c *gin.Context) {
continue
}
filteredNodes = append(filteredNodes, node)
if len(filteredNodes) >= req.PerPage {
break
}
}
req.Page++
}
common.SuccessResp(c, common.PageResp{
Content: utils.MustSliceConvert(filteredNodes, nodeToSearchResp),
Total: total,
Total: int64(len(filteredNodes)),
})
}