From 81b9a105a722ddb59ceaec77f9131695d80be495 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 27 Jul 2023 13:41:42 +0200 Subject: [PATCH] refactor: factor out configuration section cache population MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/Configuration.ts | 62 +++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 2491757b..f01decea 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -60,33 +60,8 @@ export class Configuration { public static getConfigurationSection( sectionName: ConfigurationSection, ): T { - if (!Configuration.configurationSectionCache.has(sectionName)) { - switch (sectionName) { - case ConfigurationSection.log: - Configuration.configurationSectionCache.set(sectionName, Configuration.buildLogSection()); - break; - case ConfigurationSection.performanceStorage: - Configuration.configurationSectionCache.set( - sectionName, - Configuration.buildPerformanceStorageSection(), - ); - break; - case ConfigurationSection.worker: - Configuration.configurationSectionCache.set( - sectionName, - Configuration.buildWorkerSection(), - ); - break; - case ConfigurationSection.uiServer: - Configuration.configurationSectionCache.set( - sectionName, - Configuration.buildUIServerSection(), - ); - break; - default: - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - throw new Error(`Unknown configuration section '${sectionName}'`); - } + if (!Configuration.isConfigurationSectionCached(sectionName)) { + Configuration.cacheConfigurationSection(sectionName); } return Configuration.configurationSectionCache.get(sectionName) as T; } @@ -188,6 +163,39 @@ export class Configuration { return Configuration.buildWorkerSection().processType === WorkerProcessType.dynamicPool; } + private static isConfigurationSectionCached(sectionName: ConfigurationSection): boolean { + return Configuration.configurationSectionCache.has(sectionName); + } + + private static cacheConfigurationSection(sectionName: ConfigurationSection): void { + switch (sectionName) { + case ConfigurationSection.log: + Configuration.configurationSectionCache.set(sectionName, Configuration.buildLogSection()); + break; + case ConfigurationSection.performanceStorage: + Configuration.configurationSectionCache.set( + sectionName, + Configuration.buildPerformanceStorageSection(), + ); + break; + case ConfigurationSection.worker: + Configuration.configurationSectionCache.set( + sectionName, + Configuration.buildWorkerSection(), + ); + break; + case ConfigurationSection.uiServer: + Configuration.configurationSectionCache.set( + sectionName, + Configuration.buildUIServerSection(), + ); + break; + default: + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + throw new Error(`Unknown configuration section '${sectionName}'`); + } + } + private static buildUIServerSection(): UIServerConfiguration { if (hasOwnProp(Configuration.getConfigurationData(), 'uiWebSocketServer')) { console.error( -- 2.34.1