From 44bb21d4c92c0999b7b8fd43ed498dd5aeefc884 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 25 Jul 2023 17:24:34 +0200 Subject: [PATCH] perf: only sort charging schdule periods if needed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStationUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { -- 2.34.1