From 4aa5794fdea5775c1513b825a6f781634d8b5cad Mon Sep 17 00:00:00 2001 From: Rafael Tapia Date: Wed, 22 Mar 2023 09:48:14 -0300 Subject: [PATCH] fix: Apps.engine resource consumption (#28514) Co-authored-by: Douglas Gubert <1810309+d-gubert@users.noreply.github.com> --- .../ee/server/apps/communication/rest.js | 2 +- .../server/services/apps-engine/service.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/meteor/ee/server/apps/communication/rest.js b/apps/meteor/ee/server/apps/communication/rest.js index fbbae6408098..1099eaa9de85 100644 --- a/apps/meteor/ee/server/apps/communication/rest.js +++ b/apps/meteor/ee/server/apps/communication/rest.js @@ -1007,7 +1007,7 @@ export class AppsRestApi { const updated = []; this.bodyParams.settings.forEach((s) => { - if (settings[s.id]) { + if (settings[s.id] && settings[s.id].value !== s.value) { Promise.await(manager.getSettingsManager().updateAppSetting(this.urlParams.id, s)); // Updating? updated.push(s); diff --git a/apps/meteor/server/services/apps-engine/service.ts b/apps/meteor/server/services/apps-engine/service.ts index 035664335191..0c481c168452 100644 --- a/apps/meteor/server/services/apps-engine/service.ts +++ b/apps/meteor/server/services/apps-engine/service.ts @@ -25,6 +25,13 @@ export class AppsEngineService extends ServiceClassInternal implements IAppsEngi }); this.onEvent('apps.added', async (appId: string): Promise => { + // if the app already exists in this instance, don't load it again + const app = Apps.getManager()?.getOneById(appId); + + if (app) { + return; + } + await (Apps.getManager() as any)?.loadOne(appId); }); @@ -64,7 +71,16 @@ export class AppsEngineService extends ServiceClassInternal implements IAppsEngi } }); - this.onEvent('apps.settingUpdated', async (appId: string, setting: ISetting): Promise => { + this.onEvent('apps.settingUpdated', async (appId: string, setting: ISetting & { id: string }): Promise => { + const app = Apps.getManager()?.getOneById(appId); + const oldSetting = app?.getStorageItem().settings[setting.id].value; + + // avoid updating the setting if the value is the same, + // which caused an infinite loop + if (oldSetting === setting.value) { + return; + } + const appManager = Apps.getManager(); if (!appManager) { return;