From b75c68e15ecfebbc0e0333499b015b75fe935082 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 8 Oct 2025 18:50:38 +0200 Subject: [PATCH] fix: ensure UI server charging station templates cache is populated at restart MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 7 +++++-- .../ui-server/AbstractUIServer.ts | 20 +++++++++++++++++-- .../ui-services/AbstractUIService.ts | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 52abb188..d7dcb119 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -223,6 +223,11 @@ export class Bootstrap extends EventEmitter { ) await this.storage?.open() } + this.uiServer.setChargingStationTemplates( + Configuration.getStationTemplateUrls()?.map(stationTemplateUrl => + buildTemplateName(stationTemplateUrl.file) + ) + ) if ( !this.uiServerStarted && Configuration.getConfigurationSection( @@ -358,7 +363,6 @@ export class Bootstrap extends EventEmitter { provisioned: stationTemplateUrl.provisionedNumberOfStations ?? 0, started: 0, }) - this.uiServer.chargingStationTemplates.add(templateName) } if (this.templateStatistics.size !== stationTemplateUrls.length) { console.error( @@ -509,7 +513,6 @@ export class Bootstrap extends EventEmitter { this.uiServer.stop() this.uiServerStarted = false } - this.initializeCounters() // FIXME: initialize worker implementation only if the worker section has changed this.initializeWorkerImplementation( Configuration.getConfigurationSection(ConfigurationSection.worker) diff --git a/src/charging-station/ui-server/AbstractUIServer.ts b/src/charging-station/ui-server/AbstractUIServer.ts index 7f0ff345..f9bd5575 100644 --- a/src/charging-station/ui-server/AbstractUIServer.ts +++ b/src/charging-station/ui-server/AbstractUIServer.ts @@ -26,9 +26,7 @@ import { getUsernameAndPasswordFromAuthorizationToken } from './UIServerUtils.js const moduleName = 'AbstractUIServer' export abstract class AbstractUIServer { - public readonly chargingStationTemplates: Set protected readonly httpServer: Http2Server | Server - protected readonly responseHandlers: Map< `${string}-${string}-${string}-${string}-${string}`, ServerResponse | WebSocket @@ -37,6 +35,7 @@ export abstract class AbstractUIServer { protected readonly uiServices: Map private readonly chargingStations: Map + private readonly chargingStationTemplates: Set public constructor (protected readonly uiServerConfiguration: UIServerConfiguration) { this.chargingStations = new Map() @@ -93,10 +92,18 @@ export abstract class AbstractUIServer { return this.chargingStations.size } + public getChargingStationTemplates (): string[] { + return [...this.chargingStationTemplates.values()] + } + public hasChargingStationData (hashId: string): boolean { return this.chargingStations.has(hashId) } + public hasChargingStationTemplates (template: string): boolean { + return this.chargingStationTemplates.has(template) + } + public hasResponseHandler (uuid: `${string}-${string}-${string}-${string}-${string}`): boolean { return this.responseHandlers.has(uuid) } @@ -126,6 +133,15 @@ export abstract class AbstractUIServer { } } + public setChargingStationTemplates (templates: string[] | undefined): void { + if (templates == null) { + return + } + for (const template of templates) { + this.chargingStationTemplates.add(template) + } + } + public abstract start (): void public stop (): void { diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 789e7456..c67f21b3 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -241,7 +241,7 @@ export abstract class AbstractUIService { status: ResponseStatus.FAILURE, } satisfies ResponsePayload } - if (!this.uiServer.chargingStationTemplates.has(template)) { + if (!this.uiServer.hasChargingStationTemplates(template)) { return { errorMessage: `Template '${template}' not found`, status: ResponseStatus.FAILURE, @@ -290,7 +290,7 @@ export abstract class AbstractUIService { private handleListTemplates (): ResponsePayload { return { status: ResponseStatus.SUCCESS, - templates: [...this.uiServer.chargingStationTemplates.values()], + templates: this.uiServer.getChargingStationTemplates(), } satisfies ResponsePayload } -- 2.43.0