korbit-ai[bot] commented on code in PR #34660:
URL: https://github.com/apache/superset/pull/34660#discussion_r2270725469


##########
superset-frontend/src/dashboard/util/activeAllDashboardFilters.ts:
##########
@@ -16,14 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { DataMaskStateWithId, PartialFilters } from '@superset-ui/core';
+import {
+  DataMaskStateWithId,
+  DataMaskWithId,
+  JsonObject,
+  PartialFilters,
+} from '@superset-ui/core';
 import { ActiveFilters, ChartConfiguration } from '../types';
 
 export const getRelevantDataMask = (
   dataMask: DataMaskStateWithId,
-  filterId: string,
-): DataMaskStateWithId =>
-  dataMask[filterId] ? { [filterId]: dataMask[filterId] } : {};
+  prop: keyof DataMaskWithId,
+): JsonObject =>
+  Object.fromEntries(
+    Object.values(dataMask)
+      .filter(item => item[prop])
+      .map(item => [item.id, item[prop]]),
+  );

Review Comment:
   ### Redundant Array Iterations <sub>![category 
Performance](https://img.shields.io/badge/Performance-4f46e5)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The code performs two separate array iterations (filter and map) when a 
single iteration would suffice.
   
   
   ###### Why this matters
   Using separate filter and map operations creates unnecessary array 
traversals, impacting performance especially with large dataMask objects.
   
   ###### Suggested change ∙ *Feature Preview*
   Combine filter and map operations into a single reduce operation:
   ```typescript
   Object.fromEntries(
     Object.values(dataMask).reduce((acc, item) => {
       if (item[prop]) acc.push([item.id, item[prop]]);
       return acc;
     }, [] as [string, unknown][])
   );
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fe96e631-702a-446a-9e55-9f244331574b/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fe96e631-702a-446a-9e55-9f244331574b?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fe96e631-702a-446a-9e55-9f244331574b?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fe96e631-702a-446a-9e55-9f244331574b?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fe96e631-702a-446a-9e55-9f244331574b)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:260dacbd-bb36-4568-adbb-4955db5063cf -->
   
   
   [](260dacbd-bb36-4568-adbb-4955db5063cf)



-- 
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-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to