bito-code-review[bot] commented on PR #39894:
URL: https://github.com/apache/superset/pull/39894#issuecomment-4381797757
<!-- Bito Reply -->
Yes, the suggestion is valid — the race condition can occur when multiple
FilterValue components mount simultaneously, each dispatching
fetchDatasourceMetadata without deduplication, leading to duplicate API
requests. To resolve this, modify the fetchDatasourceMetadata thunk in
src/dashboard/actions/datasources.ts to track in-flight requests using a
module-level Map. There are no other comments on this PR.
**superset-frontend/src/dashboard/actions/datasources.ts**
```
const pendingFetches = new Map();
export const fetchDatasourceMetadata = (key) => (dispatch, getState) => {
if (getState().datasources[key]) return;
if (pendingFetches.has(key)) return;
const promise = SupersetClient.get({ endpoint:
`/superset/fetch_datasource_metadata?datasourceKey=${key}` })
.then(data => {
dispatch(setDatasource(key, data));
pendingFetches.delete(key);
})
.catch(() => pendingFetches.delete(key));
pendingFetches.set(key, promise);
};
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]