From ba62a535da8d31400787113da1f77282967abb65 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 24 Mar 2023 22:35:16 +0100 Subject: [PATCH] perf(simulator): build once address for tags caches addressable indexes cache MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/AuthorizedTagsCache.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/charging-station/AuthorizedTagsCache.ts b/src/charging-station/AuthorizedTagsCache.ts index b63387ed..edb69538 100644 --- a/src/charging-station/AuthorizedTagsCache.ts +++ b/src/charging-station/AuthorizedTagsCache.ts @@ -60,19 +60,21 @@ export class AuthorizedTagsCache { private getRandomIdTag(hashId: string, file: string): string { const tags = this.getAuthorizedTags(file); + const addressableKey = file + hashId; this.tagsCachesAddressableIndexes.set( - file + hashId, + addressableKey, Math.floor(Utils.secureRandom() * tags.length) ); - return tags[this.tagsCachesAddressableIndexes.get(file + hashId)]; + return tags[this.tagsCachesAddressableIndexes.get(addressableKey)]; } private getRoundRobinIdTag(hashId: string, file: string): string { const tags = this.getAuthorizedTags(file); - const idTagIndex = this.tagsCachesAddressableIndexes.get(file + hashId) ?? 0; + const addressableKey = file + hashId; + const idTagIndex = this.tagsCachesAddressableIndexes.get(addressableKey) ?? 0; const idTag = tags[idTagIndex]; this.tagsCachesAddressableIndexes.set( - file + hashId, + addressableKey, idTagIndex === tags.length - 1 ? 0 : idTagIndex + 1 ); return idTag; @@ -82,11 +84,12 @@ export class AuthorizedTagsCache { const file = ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo); const tags = this.getAuthorizedTags(file); const hashId = chargingStation.stationInfo.hashId; + const addressableKey = file + hashId; this.tagsCachesAddressableIndexes.set( - file + hashId, + addressableKey, (chargingStation.index - 1 + (connectorId - 1)) % tags.length ); - return tags[this.tagsCachesAddressableIndexes.get(file + hashId)]; + return tags[this.tagsCachesAddressableIndexes.get(addressableKey)]; } private hasTags(file: string): boolean { -- 2.34.1