-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Transforms: Improve data view checks. (#181892)
## Summary Part of #181603. For some of the actions in the transform list we need to identify if there's a data view for the target index. The way we identified this was quite inefficient. We had poor caching in place and fetched info for all data views including fields — this can be quite expensive queries! This update fixes the approach and switches to using `dataViews.getIdsWithTitle()` in combination with `useQuery()` to bring the caching in line with how we load and refresh the rest of the transform list. Before: Lots of field caps requests! <img width="1672" alt="image" src="https://github.com/elastic/kibana/assets/230104/ff7a0bbf-21e2-48b8-be7e-d9344d478ae6"> After: We do just 1 `_search` request that gets the data view ids/titles: <img width="610" alt="image" src="https://github.com/elastic/kibana/assets/230104/985c4b7d-94f8-4d65-9c2f-79bacad29cda"> ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- Loading branch information
Showing
9 changed files
with
85 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/transform/public/app/hooks/use_get_data_views_title_id_map.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import type { IHttpFetchError } from '@kbn/core-http-browser'; | ||
|
||
import { TRANSFORM_REACT_QUERY_KEYS } from '../../../common/constants'; | ||
|
||
import { useAppDependencies } from '../app_dependencies'; | ||
|
||
type DataViewListTitleIdMap = Record<string, string>; | ||
|
||
export const useGetDataViewsTitleIdMap = () => { | ||
const { data } = useAppDependencies(); | ||
|
||
return useQuery<DataViewListTitleIdMap, IHttpFetchError>( | ||
[TRANSFORM_REACT_QUERY_KEYS.GET_DATA_VIEW_IDS_WITH_TITLE], | ||
async () => { | ||
return (await data.dataViews.getIdsWithTitle(true)).reduce<Record<string, string>>( | ||
(acc, { id, title }) => { | ||
acc[title] = id; | ||
return acc; | ||
}, | ||
{} | ||
); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters