Skip to content

Commit

Permalink
[ML] Transforms: Reduce rerenders and multiple fetches of source inde…
Browse files Browse the repository at this point in the history
…x on transform wizard load. (#160979)

Adds checks to avoid unnecessary initial rerenders and refetches of data
when loading the transform wizard. This reduces rerenders from 14 to 11
and more importantly the request to fetch index data is triggered only
once instead of three times. One of the requests even triggered an error
which could briefly trigger a callout on slower connections.
  • Loading branch information
walterra committed Jul 10, 2023
1 parent ea53763 commit fc4edd6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions x-pack/plugins/transform/public/app/hooks/use_index_data.ts
Expand Up @@ -86,6 +86,9 @@ export const useIndexData = (
};

useEffect(() => {
if (dataView.timeFieldName !== undefined && timeRangeMs === undefined) {
return;
}
const abortController = new AbortController();

// Fetch 500 random documents to determine populated fields.
Expand Down Expand Up @@ -197,6 +200,9 @@ export const useIndexData = (
}, [JSON.stringify([query, timeRangeMs])]);

useEffect(() => {
if (typeof dataViewFields === 'undefined') {
return;
}
const abortController = new AbortController();

const fetchDataGridData = async function () {
Expand Down

0 comments on commit fc4edd6

Please sign in to comment.