From: Jérôme Benoit Date: Tue, 25 Jul 2023 15:24:34 +0000 (+0200) Subject: perf: only sort charging schdule periods if needed X-Git-Tag: v1.2.20~148 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=44bb21d4c92c0999b7b8fd43ed498dd5aeefc884;p=e-mobility-charging-stations-simulator.git perf: only sort charging schdule periods if needed Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index fd6079d0..5feec883 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -738,7 +738,6 @@ const getLimitFromChargingProfiles = ( isValidDate(chargingSchedule.startSchedule) && isAfter(addSeconds(chargingSchedule.startSchedule!, chargingSchedule.duration!), currentDate) ) { - chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod); if (isNotEmptyArray(chargingSchedule.chargingSchedulePeriod)) { // Handling of only one schedule period if ( @@ -752,6 +751,7 @@ const getLimitFromChargingProfiles = ( logger.debug(debugLogMsg, result); return result; } + chargingSchedule.chargingSchedulePeriod.sort((a, b) => a.startPeriod - b.startPeriod); let lastButOneSchedule: ChargingSchedulePeriod | undefined; // Search for the right schedule period for (const schedulePeriod of chargingSchedule.chargingSchedulePeriod) {