From 7af183e79b63c60d72449a4eecb7e996927ec156 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 26 Mar 2023 19:16:42 +0200 Subject: [PATCH] refactor: add helper to build content addressable key for id tags cache indexes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/IdTagsCache.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/charging-station/IdTagsCache.ts b/src/charging-station/IdTagsCache.ts index 48ecb552..f19f66f3 100644 --- a/src/charging-station/IdTagsCache.ts +++ b/src/charging-station/IdTagsCache.ts @@ -58,7 +58,7 @@ export class IdTagsCache { private getRandomIdTag(hashId: string, file: string): string { const idTags = this.getIdTags(file); - const addressableKey = file + hashId; + const addressableKey = this.getIdTagsCacheAddressableKey(file, hashId); this.idTagsCachesAddressableIndexes.set( addressableKey, Math.floor(Utils.secureRandom() * idTags.length) @@ -68,7 +68,7 @@ export class IdTagsCache { private getRoundRobinIdTag(hashId: string, file: string): string { const idTags = this.getIdTags(file); - const addressableKey = file + hashId; + const addressableKey = this.getIdTagsCacheAddressableKey(file, hashId); const idTagIndex = this.idTagsCachesAddressableIndexes.get(addressableKey) ?? 0; const idTag = idTags[idTagIndex]; this.idTagsCachesAddressableIndexes.set( @@ -82,7 +82,7 @@ export class IdTagsCache { const file = ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo); const idTags = this.getIdTags(file); const hashId = chargingStation.stationInfo.hashId; - const addressableKey = file + hashId; + const addressableKey = this.getIdTagsCacheAddressableKey(file, hashId); this.idTagsCachesAddressableIndexes.set( addressableKey, (chargingStation.index - 1 + (connectorId - 1)) % idTags.length @@ -144,6 +144,10 @@ export class IdTagsCache { } } + private getIdTagsCacheAddressableKey(prefix: string, uid: string): string { + return `${prefix}${uid}`; + } + private getIdTagsFromFile(file: string): string[] { let idTags: string[] = []; if (file) { -- 2.34.1