You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/03/04 18:36:13 UTC
Re: [PR] perf(explore): reuse chart query data in Results tab [superset]
Copilot commented on code in PR #38165:
URL: https://github.com/apache/superset/pull/38165#discussion_r2885418683
##########
superset-frontend/src/explore/components/DataTablesPane/components/useResultsPane.tsx:
##########
@@ -81,33 +108,34 @@ export const useResultsPane = ({
setForceQuery?.(false);
}
setIsLoading(false);
+ return;
}
- if (isRequest && !cache.has(queryFormData)) {
- setIsLoading(true);
- getChartDataRequest({
- formData: queryFormData,
- force: queryForce,
- resultFormat: 'json',
- resultType: 'results',
- ownState,
+
+ // Fallback: fetch from API (legacy charts without queriesResponse)
+ setIsLoading(true);
+ getChartDataRequest({
+ formData: queryFormData,
+ force: queryForce,
+ resultFormat: 'json',
+ resultType: 'results',
+ ownState,
+ })
+ .then(({ json }) => {
+ setResultResp(ensureIsArray(json.result) as QueryResultInterface[]);
+ setResponseError('');
+ cache.set(queryFormData, json.result);
+ if (queryForce) {
+ setForceQuery?.(false);
+ }
})
- .then(({ json }) => {
- setResultResp(ensureIsArray(json.result) as QueryResultInterface[]);
- setResponseError('');
- cache.set(queryFormData, json.result);
- if (queryForce) {
- setForceQuery?.(false);
- }
- })
- .catch(response => {
- getClientErrorObject(response).then(({ error, message }) => {
- setResponseError(error || message || t('Sorry, an error occurred'));
- });
- })
- .finally(() => {
- setIsLoading(false);
+ .catch(response => {
+ getClientErrorObject(response).then(({ error, message }) => {
+ setResponseError(error || message || t('Sorry, an error occurred'));
});
- }
+ })
+ .finally(() => {
+ setIsLoading(false);
+ });
}, [queryFormData, isRequest]);
Review Comment:
`useEffect` now depends on `queriesResponse`/`queryForce`/`ownState`/`errorMessage` (and uses `setForceQuery`), but the dependency array is still `[queryFormData, isRequest]`. This can prevent the new reuse-path from running when `queriesResponse` arrives/changes (e.g., after the chart request completes without `queryFormData` changing) and may also trigger `react-hooks/exhaustive-deps` lint failures. Update the dependencies or refactor (e.g., separate effect keyed by `queriesResponse` + `isRequest`) so results update reliably without an extra API call.
```suggestion
}, [
queryFormData,
isRequest,
queriesResponse,
queryForce,
ownState,
errorMessage,
]);
```
##########
superset-frontend/src/explore/components/DataTablesPane/components/useResultsPane.tsx:
##########
@@ -72,7 +74,32 @@ export const useResultsPane = ({
useEffect(() => {
// it's an invalid formData when gets a errorMessage
if (errorMessage) return;
- if (isRequest && cache.has(queryFormData)) {
+ if (!isRequest) return;
+
+ // Reuse chart data from Redux when available. The chart visualization
+ // query and the results query produce identical SQL on the backend,
+ // so there is no need for a separate network request.
+ if (queriesResponse?.length && 'colnames' in queriesResponse[0]) {
+ const mapped = queriesResponse.map(q => {
Review Comment:
The new branch that reuses `queriesResponse` (skipping `getChartDataRequest`) isn’t covered by existing tests. Consider adding a unit test that passes a v1-shaped `queriesResponse` and asserts no network request is made and the table renders from Redux data, plus a test that verifies an update when `queriesResponse` changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org