Skip to content

Commit

Permalink
[Bug] performance improvement (#1176)
Browse files Browse the repository at this point in the history
* upadtechart rerenders fixing: in progress

Signed-off-by: Ramneet Chopra <ramneet_chopra@persistent.com>

* logs/comments removed

Signed-off-by: Ramneet Chopra <ramneet_chopra@persistent.com>

Signed-off-by: Ramneet Chopra <ramneet_chopra@persistent.com>
  • Loading branch information
ramneet-persistent authored Oct 21, 2022
1 parent 8e055ec commit af3b3d3
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export const Explorer = ({
const curQuery = queryRef.current;
const rawQueryStr = buildQuery(appBasedRef.current, curQuery![RAW_QUERY]);
const curIndex = getIndexPatternFromRawQuery(rawQueryStr);

if (isEmpty(rawQueryStr)) return;

if (isEmpty(curIndex)) {
Expand All @@ -333,7 +334,6 @@ export const Explorer = ({
}

let curTimestamp: string = curQuery![SELECTED_TIMESTAMP];

if (isEmpty(curTimestamp)) {
const defaultTimestamp = await getDefaultTimestampByIndexPattern(curIndex);
if (isEmpty(defaultTimestamp.default_timestamp)) {
Expand Down Expand Up @@ -420,6 +420,99 @@ export const Explorer = ({
}
};

// for testing purpose only: fix for multiple rerenders in case of update chart
const fetchDataUpdateChart = async (
startingTime?: string | undefined,
endingTime?: string | undefined,
updatedQuery?: any
) => {
const curQuery = updatedQuery.query;
const rawQueryStr = curQuery[RAW_QUERY];
const curIndex = getIndexPatternFromRawQuery(rawQueryStr);
if (isEmpty(rawQueryStr)) return;

if (isEmpty(curIndex)) {
setToast('Query does not include valid index.', 'danger');
return;
}

let curTimestamp: string = curQuery![SELECTED_TIMESTAMP];
if (isEmpty(curTimestamp)) {
const defaultTimestamp = await getDefaultTimestampByIndexPattern(curIndex);
if (isEmpty(defaultTimestamp.default_timestamp)) {
setToast(defaultTimestamp.message, 'danger');
return;
}
curTimestamp = defaultTimestamp.default_timestamp;
if (defaultTimestamp.hasSchemaConflict) {
setToast(defaultTimestamp.message, 'danger');
}
}

if (isEqual(typeof startingTime, 'undefined') && isEqual(typeof endingTime, 'undefined')) {
startingTime = curQuery![SELECTED_DATE_RANGE][0];
endingTime = curQuery![SELECTED_DATE_RANGE][1];
}

// compose final query
const finalQuery = composeFinalQuery(
curQuery,
startingTime!,
endingTime!,
curTimestamp,
isLiveTailOnRef.current
);

await dispatch(
changeQuery({
tabId,
query: {
finalQuery,
[SELECTED_TIMESTAMP]: curTimestamp,
[RAW_QUERY]: rawQueryStr,
},
})
);

// search
if (finalQuery.match(PPL_STATS_REGEX)) {
getVisualizations();
} else {
findAutoInterval(startTime, endTime);
if (isLiveTailOnRef.current) {
getLiveTail(undefined, (error) => {
const formattedError = formatError(error.name, error.message, error.body.message);
notifications.toasts.addError(formattedError, {
title: 'Error fetching events',
});
});
} else {
getEvents(undefined, (error) => {
const formattedError = formatError(error.name, error.message, error.body.message);
notifications.toasts.addError(formattedError, {
title: 'Error fetching events',
});
});
}
getCountVisualizations(minInterval);
}

// for comparing usage if for the same tab, user changed index from one to another
if (!isLiveTailOnRef.current) {
setPrevIndex(curTimestamp);
if (!queryRef.current!.isLoaded) {
dispatch(
changeQuery({
tabId,
query: {
isLoaded: true,
},
})
);
}
}
};

const isIndexPatternChanged = (currentQuery: string, prevTabQuery: string) =>
!isEqual(getIndexPatternFromRawQuery(currentQuery), getIndexPatternFromRawQuery(prevTabQuery));

Expand Down Expand Up @@ -1327,6 +1420,7 @@ export const Explorer = ({
handleQueryChange,
setTempQuery,
fetchData,
fetchDataUpdateChart,
explorerFields,
explorerData,
http,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export const DataConfigPanelItem = ({
queryManager,
}: DataConfigPanelProps) => {
const dispatch = useDispatch();
const { tabId, handleQueryChange, fetchData, curVisId } = useContext<any>(TabContext);
const { tabId, handleQueryChange, fetchData, fetchDataUpdateChart, curVisId } = useContext<any>(
TabContext
);
const { data } = visualizations;
const { data: vizData = {}, metadata: { fields = [] } = {} } = data?.rawVizData;
const {
Expand Down Expand Up @@ -204,6 +206,7 @@ export const DataConfigPanelItem = ({
setIsAddConfigClicked(false);
};

// updateChart is fixed for multiple rerenders and this is only for testing
const updateChart = (updatedConfigList = configList) => {
if (visualizations.vis.name === VIS_CHART_TYPES.Histogram) {
dispatch(
Expand All @@ -226,37 +229,14 @@ export const DataConfigPanelItem = ({
.queryBuilder()
.build(data.query.rawQuery, composeAggregations(updatedConfigList, statsTokens));

batch(async () => {
await handleQueryChange(newQuery);
await dispatch(
changeQuery({
tabId,
query: {
...data.query,
[RAW_QUERY]: newQuery,
},
})
);
await fetchData();
await dispatch(
changeVizConfig({
tabId,
vizId: visualizations.vis.name,
data: {
dataConfig: {
...userConfigs.dataConfig,
[GROUPBY]: updatedConfigList[GROUPBY],
[AGGREGATIONS]: updatedConfigList[AGGREGATIONS],
[BREAKDOWNS]: updatedConfigList[BREAKDOWNS],
[SPAN]:
!isEmpty(updatedConfigList[GROUPBY]) && !isEmpty(updatedConfigList[AGGREGATIONS])
? updatedConfigList?.span
: undefined,
},
},
})
);
});
const updatedQuery = {
tabId,
query: {
...data.query,
[RAW_QUERY]: newQuery,
},
};
fetchDataUpdateChart(undefined, undefined, updatedQuery);
}
};

Expand Down

0 comments on commit af3b3d3

Please sign in to comment.