Search: Improvements for starred dashboard search (#64758)
* improvements for starred dashboard search * fix workflows for the case when no dashboards are starred * PR feedback (don't query DB if starred dashboards and requested but no starred IDs are found) and linting * return empty list not null in case of no starred dashboards * return empty list not null in case of no starred dashboards pt 2 * return empty list not null in case of no starred dashboards pt 3
This commit is contained in:
@@ -345,25 +345,20 @@ func (s *ServiceImpl) buildStarredItemsNavLinks(c *contextmodel.ReqContext) ([]*
|
||||
return nil, err
|
||||
}
|
||||
|
||||
starredDashboards := []*dashboards.Dashboard{}
|
||||
starredDashboardsCounter := 0
|
||||
for dashboardId := range starredDashboardResult.UserStars {
|
||||
if len(starredDashboardResult.UserStars) > 0 {
|
||||
var ids []int64
|
||||
for id := range starredDashboardResult.UserStars {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
starredDashboards, err := s.dashboardService.GetDashboards(c.Req.Context(), &dashboards.GetDashboardsQuery{DashboardIDs: ids, OrgID: c.OrgID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Set a loose limit to the first 50 starred dashboards found
|
||||
if starredDashboardsCounter > 50 {
|
||||
break
|
||||
if len(starredDashboards) > 50 {
|
||||
starredDashboards = starredDashboards[:50]
|
||||
}
|
||||
starredDashboardsCounter++
|
||||
query := &dashboards.GetDashboardQuery{
|
||||
ID: dashboardId,
|
||||
OrgID: c.OrgID,
|
||||
}
|
||||
queryResult, err := s.dashboardService.GetDashboard(c.Req.Context(), query)
|
||||
if err == nil {
|
||||
starredDashboards = append(starredDashboards, queryResult)
|
||||
}
|
||||
}
|
||||
|
||||
if len(starredDashboards) > 0 {
|
||||
sort.Slice(starredDashboards, func(i, j int) bool {
|
||||
return starredDashboards[i].Title < starredDashboards[j].Title
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user