korbit-ai[bot] commented on code in PR #35341:
URL: https://github.com/apache/superset/pull/35341#discussion_r2391807002
##########
superset-frontend/src/SqlLab/components/TableElement/index.tsx:
##########
@@ -103,6 +103,19 @@ const TableElement = ({ table, ...props }:
TableElementProps) => {
},
{ skip: !expanded },
);
+ const tableData = {
+ ...tableMetadata,
+ ...tableExtendedMetadata,
+ };
+ const queryEditors = useSelector<SqlLabRootState, QueryEditor[]>(
+ state => state.sqlLab.queryEditors,
+ );
Review Comment:
### Inefficient Redux selector fetching entire array <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The useSelector hook is called on every render to fetch the entire
queryEditors array from Redux state, even when only one specific query editor
is needed.
###### Why this matters
This causes unnecessary re-renders and memory allocation when the
queryEditors array changes, even if the specific query editor being used hasn't
changed. The component will re-render whenever any query editor in the array is
modified.
###### Suggested change ∙ *Feature Preview*
Use a memoized selector that only returns the specific query editor needed:
```typescript
const queryEditor = useSelector<SqlLabRootState, QueryEditor | undefined>(
state => state.sqlLab.queryEditors.find(
qe => qe.id === table.queryEditorId || qe.tabViewId ===
table.queryEditorId
),
(left, right) => left?.tabViewId === right?.tabViewId
);
```
Then remove the separate `find` operation and use `queryEditor` directly.
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/19cf6543-7cb6-44b3-8a2c-78325eafc676/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/19cf6543-7cb6-44b3-8a2c-78325eafc676?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/19cf6543-7cb6-44b3-8a2c-78325eafc676?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/19cf6543-7cb6-44b3-8a2c-78325eafc676?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/19cf6543-7cb6-44b3-8a2c-78325eafc676)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:1e80ea00-d9d4-4f50-8df8-655a6ed5ccd9 -->
[](1e80ea00-d9d4-4f50-8df8-655a6ed5ccd9)
--
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]