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


##########
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:
   Yes, we can benchmark both implementations using simple performance tests:
   
   ```ts
   // Test function
   function benchmarkImplementations(size: number) {
     const dataMask = Array(size).fill(null).reduce((acc, _, i) => ({
       ...acc,
       [`id${i}`]: { id: `id${i}`, extraFormData: i % 2 ? null : {} }
     }), {});
   
     console.time('filter+map');
     for(let i = 0; i < 1000; i++) {
       Object.fromEntries(
         Object.values(dataMask)
           .filter(item => item.extraFormData)
           .map(item => [item.id, item.extraFormData])
       );
     }
     console.timeEnd('filter+map');
   
     console.time('reduce');
     for(let i = 0; i < 1000; i++) {
       Object.fromEntries(
         Object.values(dataMask).reduce((acc, item) => {
           if (item.extraFormData) acc.push([item.id, item.extraFormData]);
           return acc;
         }, [])
       );
     }
     console.timeEnd('reduce');
   }
   ```



-- 
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]

Reply via email to