Chore: Remove result field from search (#65583)
remove result field from search
This commit is contained in:
@@ -40,12 +40,10 @@ type Query struct {
|
||||
FolderIds []int64
|
||||
Permission dashboards.PermissionType
|
||||
Sort string
|
||||
|
||||
Result model.HitList
|
||||
}
|
||||
|
||||
type Service interface {
|
||||
SearchHandler(context.Context, *Query) error
|
||||
SearchHandler(context.Context, *Query) (model.HitList, error)
|
||||
SortOptions() []model.SortOption
|
||||
}
|
||||
|
||||
@@ -57,19 +55,18 @@ type SearchService struct {
|
||||
dashboardService dashboards.DashboardService
|
||||
}
|
||||
|
||||
func (s *SearchService) SearchHandler(ctx context.Context, query *Query) error {
|
||||
func (s *SearchService) SearchHandler(ctx context.Context, query *Query) (model.HitList, error) {
|
||||
starredQuery := star.GetUserStarsQuery{
|
||||
UserID: query.SignedInUser.UserID,
|
||||
}
|
||||
staredDashIDs, err := s.starService.GetByUser(ctx, &starredQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// No starred dashboards will be found
|
||||
if query.IsStarred && len(staredDashIDs.UserStars) == 0 {
|
||||
query.Result = model.HitList{}
|
||||
return nil
|
||||
return model.HitList{}, nil
|
||||
}
|
||||
|
||||
// filter by starred dashboard IDs when starred dashboards are requested and no UID or ID filters are specified to improve query performance
|
||||
@@ -98,7 +95,7 @@ func (s *SearchService) SearchHandler(ctx context.Context, query *Query) error {
|
||||
|
||||
hits, err := s.dashboardService.SearchDashboards(ctx, &dashboardQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if query.Sort == "" {
|
||||
@@ -114,17 +111,15 @@ func (s *SearchService) SearchHandler(ctx context.Context, query *Query) error {
|
||||
|
||||
// filter for starred dashboards if requested
|
||||
if !query.IsStarred {
|
||||
query.Result = hits
|
||||
} else {
|
||||
query.Result = model.HitList{}
|
||||
for _, dashboard := range hits {
|
||||
if dashboard.IsStarred {
|
||||
query.Result = append(query.Result, dashboard)
|
||||
}
|
||||
return hits, nil
|
||||
}
|
||||
result := model.HitList{}
|
||||
for _, dashboard := range hits {
|
||||
if dashboard.IsStarred {
|
||||
result = append(result, dashboard)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func sortedHits(unsorted model.HitList) model.HitList {
|
||||
|
||||
Reference in New Issue
Block a user