perf(simulator): filter array for undefined before running map()
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 13 Feb 2023 10:26:15 +0000 (11:26 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 13 Feb 2023 10:26:15 +0000 (11:26 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts

index 8528c0e247002a3f830d5f777e5f488f93cda99a..3a21bc7378d71161da31480e9b7e9a3d36ada4bc 100644 (file)
@@ -70,31 +70,31 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel {
       status: responsesStatus,
       hashIdsSucceeded: this.responses
         .get(uuid)
-        ?.responses.map(({ status, hashId }) => {
+        ?.responses.filter(({ hashId }) => hashId !== undefined)
+        .map(({ status, hashId }) => {
           if (status === ResponseStatus.SUCCESS) {
             return hashId;
           }
-        })
-        .filter((hashId) => hashId !== undefined),
+        }),
       ...(responsesStatus === ResponseStatus.FAILURE && {
         hashIdsFailed: this.responses
           .get(uuid)
-          ?.responses.map(({ status, hashId }) => {
+          ?.responses.filter(({ hashId }) => hashId !== undefined)
+          .map(({ status, hashId }) => {
             if (status === ResponseStatus.FAILURE) {
               return hashId;
             }
-          })
-          .filter((hashId) => hashId !== undefined),
+          }),
       }),
       ...(responsesStatus === ResponseStatus.FAILURE && {
         responsesFailed: this.responses
           .get(uuid)
-          ?.responses.map((response) => {
+          ?.responses.filter((response) => response !== undefined)
+          .map((response) => {
             if (response.status === ResponseStatus.FAILURE) {
               return response;
             }
-          })
-          .filter((response) => response !== undefined),
+          }),
       }),
     };
   }
index 9662d6353c01d72cf0267bf72e501c789ea91576..b471b6cc94e783f70a634404b5486b1aa9f30e36 100644 (file)
@@ -152,6 +152,7 @@ export abstract class AbstractUIService {
   ): void {
     if (Utils.isNotEmptyArray(payload.hashIds)) {
       payload.hashIds = payload.hashIds
+        .filter((hashId) => hashId !== undefined)
         .map((hashId) => {
           if (this.uiServer.chargingStations.has(hashId) === true) {
             return hashId;
@@ -162,8 +163,7 @@ export abstract class AbstractUIService {
               'sendBroadcastChannelRequest'
             )} Charging station with hashId '${hashId}' not found`
           );
-        })
-        .filter((hashId) => hashId !== undefined);
+        });
     }
     const expectedNumberOfResponses = Utils.isNotEmptyArray(payload.hashIds)
       ? payload.hashIds.length