From 71e00800619d08f9020fa69f39420c46b74908af Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Wed, 28 Aug 2024 17:44:39 +0000 Subject: [PATCH 1/2] fix(queryAssist): allow dataset with DATA_SOURCE type Signed-off-by: Joshua Li --- .../public/query_assist/utils/create_extension.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx index bebe250a91ce..065b2720add3 100644 --- a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx +++ b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx @@ -47,7 +47,11 @@ const getAvailableLanguages$ = (http: HttpSetup, data: DataPublicPluginSetup) => switchMap(async (query) => { // currently query assist tool relies on opensearch API to get index // mappings, external data source types (e.g. s3) are not supported - if (query.dataset?.dataSource?.type !== DEFAULT_DATA.SOURCE_TYPES.OPENSEARCH) return []; + if ( + query.dataset?.dataSource?.type !== DEFAULT_DATA.SOURCE_TYPES.OPENSEARCH && + query.dataset?.dataSource?.type !== 'DATA_SOURCE' + ) + return []; const dataSourceId = query.dataset?.dataSource?.id; return getAvailableLanguagesForDataSource(http, dataSourceId); From da68f08305348218d6644c31aba7b1da927a7247 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Wed, 28 Aug 2024 18:02:19 +0000 Subject: [PATCH 2/2] prevent multiple calls to get available languages Signed-off-by: Joshua Li --- .../public/query_assist/utils/create_extension.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx index 065b2720add3..ac56f35a7281 100644 --- a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx +++ b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx @@ -22,15 +22,25 @@ import assistantMark from '../../assets/query_assist_mark.svg'; */ const getAvailableLanguagesForDataSource = (() => { const availableLanguagesByDataSource: Map = new Map(); + const pendingRequests: Map> = new Map(); + return async (http: HttpSetup, dataSourceId: string | undefined) => { const cached = availableLanguagesByDataSource.get(dataSourceId); if (cached !== undefined) return cached; - const languages = await http + + const pendingRequest = pendingRequests.get(dataSourceId); + if (pendingRequest !== undefined) return pendingRequest; + + const languagesPromise = http .get<{ configuredLanguages: string[] }>(API.QUERY_ASSIST.LANGUAGES, { query: { dataSourceId }, }) .then((response) => response.configuredLanguages) - .catch(() => []); + .catch(() => []) + .finally(() => pendingRequests.delete(dataSourceId)); + pendingRequests.set(dataSourceId, languagesPromise); + + const languages = await languagesPromise; availableLanguagesByDataSource.set(dataSourceId, languages); return languages; };