From 4d1d8ab228680ad99ba68f44edc4507ab14f57bd Mon Sep 17 00:00:00 2001 From: Dappnodedev Date: Fri, 20 Sep 2024 08:29:16 +0000 Subject: [PATCH 1/2] Only recreate on modified user settings --- packages/stakers/src/stakerComponent.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/stakers/src/stakerComponent.ts b/packages/stakers/src/stakerComponent.ts index c159e92dc..f6e42942a 100644 --- a/packages/stakers/src/stakerComponent.ts +++ b/packages/stakers/src/stakerComponent.ts @@ -61,7 +61,7 @@ export class StakerComponent { userSettings: UserSettings; }): Promise { logs.info(`Persisting ${dnpName}`); - await this.setStakerPkgConfig({ dnpName, isInstalled: true, userSettings, forceRecreate: false }); + await this.setStakerPkgConfig({ dnpName, isInstalled: true, userSettings }); } protected async setNew({ @@ -133,14 +133,13 @@ export class StakerComponent { private async setStakerPkgConfig({ dnpName, isInstalled, - userSettings, - forceRecreate = true + userSettings }: { dnpName: string; isInstalled: boolean; userSettings: UserSettings; - forceRecreate?: boolean; }): Promise { + let forceRecreate = false; // ensure pkg installed if (!isInstalled) await packageInstall(this.dappnodeInstaller, { @@ -154,6 +153,7 @@ export class StakerComponent { if (!isMatch(userSettingsPrev, userSettings)) { composeEditor.applyUserSettings(userSettings, { dnpName }); composeEditor.write(); + forceRecreate = true; // Only recreate if userSettings changed } } From 4f0ccc40db43697c0c866ca6552e5f2719d809b4 Mon Sep 17 00:00:00 2001 From: Dappnodedev Date: Fri, 20 Sep 2024 10:12:04 +0000 Subject: [PATCH 2/2] Clean setStakerPkgConfig --- packages/stakers/src/stakerComponent.ts | 29 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/stakers/src/stakerComponent.ts b/packages/stakers/src/stakerComponent.ts index f6e42942a..48cd8bcd5 100644 --- a/packages/stakers/src/stakerComponent.ts +++ b/packages/stakers/src/stakerComponent.ts @@ -139,18 +139,33 @@ export class StakerComponent { isInstalled: boolean; userSettings: UserSettings; }): Promise { - let forceRecreate = false; - // ensure pkg installed - if (!isInstalled) + if (isInstalled) { + await this.setInstalledStakerPkgConfig({ dnpName, userSettings }); + } else { await packageInstall(this.dappnodeInstaller, { name: dnpName, userSettings: userSettings ? { [dnpName]: userSettings } : {} }); - else if (userSettings) { + } + } + + private async setInstalledStakerPkgConfig({ + dnpName, + userSettings + }: { + dnpName: string; + userSettings: UserSettings; + }): Promise { + let forceRecreate = false; + + if (userSettings) { const composeEditor = new ComposeFileEditor(dnpName, false); - const userSettingsPrev: UserSettingsAllDnps = {}; - userSettingsPrev[dnpName] = composeEditor.getUserSettings(); - if (!isMatch(userSettingsPrev, userSettings)) { + + const previousSettings: UserSettingsAllDnps = { + [dnpName]: composeEditor.getUserSettings() + }; + + if (!isMatch(previousSettings, userSettings)) { composeEditor.applyUserSettings(userSettings, { dnpName }); composeEditor.write(); forceRecreate = true; // Only recreate if userSettings changed