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:
Ieva
2023-03-16 09:20:07 +00:00
committed by GitHub
parent 8617ad688d
commit f966045129
9 changed files with 107 additions and 102 deletions
+13 -9
View File
@@ -52,22 +52,26 @@ func (api *API) GetStars(c *contextmodel.ReqContext) response.Response {
iuserstars, err := api.starService.GetByUser(c.Req.Context(), &query)
if err != nil {
return response.Error(500, "Failed to get user stars", err)
return response.Error(http.StatusInternalServerError, "Failed to get user stars", err)
}
uids := []string{}
for dashboardId := range iuserstars.UserStars {
query := &dashboards.GetDashboardQuery{
ID: dashboardId,
OrgID: c.OrgID,
if len(iuserstars.UserStars) > 0 {
var ids []int64
for id := range iuserstars.UserStars {
ids = append(ids, id)
}
starredDashboards, err := api.dashboardService.GetDashboards(c.Req.Context(), &dashboards.GetDashboardsQuery{DashboardIDs: ids, OrgID: c.OrgID})
if err != nil {
return response.ErrOrFallback(http.StatusInternalServerError, "Failed to fetch dashboards", err)
}
queryResult, err := api.dashboardService.GetDashboard(c.Req.Context(), query)
// Grafana admin users may have starred dashboards in multiple orgs. This will avoid returning errors when the dashboard is in another org
if err == nil {
uids = append(uids, queryResult.UID)
uids = make([]string, len(starredDashboards))
for i, dash := range starredDashboards {
uids[i] = dash.UID
}
}
return response.JSON(200, uids)
}