Chore: Propagate context for search (#41010)

Propagate context for search.Query, FindPersistedDashboardsQuery, 
GetUserStarsQuery. Followup on context.TODO added by #40810.

Ref #36734
This commit is contained in:
Marcus Efraimsson
2021-10-28 11:29:07 +02:00
committed by GitHub
parent 877c726246
commit 2d2f7afbde
10 changed files with 53 additions and 48 deletions
+1 -1
View File
@@ -89,7 +89,7 @@ func GetAlerts(c *models.ReqContext) response.Response {
Permission: models.PERMISSION_VIEW,
}
err := bus.Dispatch(&searchQuery)
err := bus.DispatchCtx(c.Req.Context(), &searchQuery)
if err != nil {
return response.Error(500, "List alerts failed", err)
}
+1 -1
View File
@@ -117,7 +117,7 @@ func GetPlaylistItems(c *models.ReqContext) response.Response {
func GetPlaylistDashboards(c *models.ReqContext) response.Response {
playlistID := c.ParamsInt64(":id")
playlists, err := LoadPlaylistDashboards(c.OrgId, c.SignedInUser, playlistID)
playlists, err := LoadPlaylistDashboards(c.Req.Context(), c.OrgId, c.SignedInUser, playlistID)
if err != nil {
return response.Error(500, "Could not load dashboards", err)
}
+5 -4
View File
@@ -1,6 +1,7 @@
package api
import (
"context"
"sort"
"strconv"
@@ -35,7 +36,7 @@ func populateDashboardsByID(dashboardByIDs []int64, dashboardIDOrder map[int64]i
return result, nil
}
func populateDashboardsByTag(orgID int64, signedInUser *models.SignedInUser, dashboardByTag []string, dashboardTagOrder map[string]int) dtos.PlaylistDashboardsSlice {
func populateDashboardsByTag(ctx context.Context, orgID int64, signedInUser *models.SignedInUser, dashboardByTag []string, dashboardTagOrder map[string]int) dtos.PlaylistDashboardsSlice {
result := make(dtos.PlaylistDashboardsSlice, 0)
for _, tag := range dashboardByTag {
@@ -48,7 +49,7 @@ func populateDashboardsByTag(orgID int64, signedInUser *models.SignedInUser, das
OrgId: orgID,
}
if err := bus.Dispatch(&searchQuery); err == nil {
if err := bus.DispatchCtx(ctx, &searchQuery); err == nil {
for _, item := range searchQuery.Result {
result = append(result, dtos.PlaylistDashboard{
Id: item.ID,
@@ -65,7 +66,7 @@ func populateDashboardsByTag(orgID int64, signedInUser *models.SignedInUser, das
return result
}
func LoadPlaylistDashboards(orgID int64, signedInUser *models.SignedInUser, playlistID int64) (dtos.PlaylistDashboardsSlice, error) {
func LoadPlaylistDashboards(ctx context.Context, orgID int64, signedInUser *models.SignedInUser, playlistID int64) (dtos.PlaylistDashboardsSlice, error) {
playlistItems, _ := LoadPlaylistItems(playlistID)
dashboardByIDs := make([]int64, 0)
@@ -90,7 +91,7 @@ func LoadPlaylistDashboards(orgID int64, signedInUser *models.SignedInUser, play
var k, _ = populateDashboardsByID(dashboardByIDs, dashboardIDOrder)
result = append(result, k...)
result = append(result, populateDashboardsByTag(orgID, signedInUser, dashboardByTag, dashboardTagOrder)...)
result = append(result, populateDashboardsByTag(ctx, orgID, signedInUser, dashboardByTag, dashboardTagOrder)...)
sort.Sort(result)
return result, nil
+1 -1
View File
@@ -62,7 +62,7 @@ func Search(c *models.ReqContext) response.Response {
Sort: sort,
}
err := bus.Dispatch(&searchQuery)
err := bus.DispatchCtx(c.Req.Context(), &searchQuery)
if err != nil {
return response.Error(500, "Search failed", err)
}