From: Jérôme Benoit Date: Mon, 13 Feb 2023 10:26:15 +0000 (+0100) Subject: perf(simulator): filter array for undefined before running map() X-Git-Tag: v1.1.95~66 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3ce0201e969c813052452540075b65985b3bc47e;p=e-mobility-charging-stations-simulator.git perf(simulator): filter array for undefined before running map() Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index 8528c0e2..3a21bc73 100644 --- a/src/charging-station/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/UIServiceWorkerBroadcastChannel.ts @@ -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), + }), }), }; } diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 9662d635..b471b6cc 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -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