From: Jérôme Benoit Date: Sun, 26 Mar 2023 17:16:42 +0000 (+0200) Subject: refactor: add helper to build content addressable key for id tags cache X-Git-Tag: v1.2.0-0~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7af183e79b63c60d72449a4eecb7e996927ec156;p=e-mobility-charging-stations-simulator.git refactor: add helper to build content addressable key for id tags cache indexes Signed-off-by: Jérôme Benoit --- 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) {