From df86de78d86de0635401b2d7e30c700079606cfc Mon Sep 17 00:00:00 2001 From: Alex Khomenko Date: Thu, 25 Sep 2025 08:14:26 +0300 Subject: [PATCH] Search: Use new star service (#111545) --- public/app/features/search/service/unified.ts | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/public/app/features/search/service/unified.ts b/public/app/features/search/service/unified.ts index c0514db43f9..8328c753700 100644 --- a/public/app/features/search/service/unified.ts +++ b/public/app/features/search/service/unified.ts @@ -3,9 +3,12 @@ import { isEmpty } from 'lodash'; import { DataFrame, DataFrameView, getDisplayProcessor, SelectableValue, toDataFrame } from '@grafana/data'; import { t } from '@grafana/i18n'; import { config, getBackendSrv } from '@grafana/runtime'; +import { generatedAPI, ListStarsApiResponse } from 'app/api/clients/preferences/v1alpha1'; import { getAPIBaseURL } from 'app/api/utils'; import { TermCount } from 'app/core/components/TagFilter/TagFilter'; +import { contextSrv } from 'app/core/core'; import kbn from 'app/core/utils/kbn'; +import { dispatch } from 'app/store/store'; import { deletedDashboardsCache } from './deletedDashboardsCache'; import { @@ -16,7 +19,7 @@ import { SearchQuery, SearchResultMeta, } from './types'; -import { replaceCurrentFolderQuery, filterSearchResults } from './utils'; +import { filterSearchResults, replaceCurrentFolderQuery } from './utils'; // The backend returns an empty frame with a special name to indicate that the indexing engine is being rebuilt, // and that it can not serve any search requests. We are temporarily using the old SQL Search API as a fallback when that happens. @@ -73,7 +76,22 @@ export class UnifiedSearcher implements GrafanaSearcher { throw new Error('facets not supported!'); } // get the starred dashboards - const starsIds = await getBackendSrv().get('api/user/stars'); + let starsIds: string[] | undefined = []; + if (config.featureToggles.starsFromAPIServer) { + const name = `user-${contextSrv.user.uid}`; + const result: { data: ListStarsApiResponse } = await dispatch( + generatedAPI.endpoints.listStars.initiate({ + fieldSelector: `metadata.name=${name}`, + }) + ); + starsIds = + result.data.items?.[0].spec.resource.find( + (info) => info.group === 'dashboard.grafana.app' && info.kind === 'Dashboard' + )?.names || []; + } else { + starsIds = await getBackendSrv().get('api/user/stars'); + } + if (starsIds?.length) { return this.doSearchQuery({ ...query,