Skip to content

Commit

Permalink
fix: Apps.engine resource consumption (#28514)
Browse files Browse the repository at this point in the history
Co-authored-by: Douglas Gubert <1810309+d-gubert@users.noreply.github.com>
  • Loading branch information
tapiarafael and d-gubert committed Mar 22, 2023
1 parent d4cb1b2 commit 4aa5794
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/apps/communication/rest.js
Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion apps/meteor/server/services/apps-engine/service.ts
Expand Up @@ -25,6 +25,13 @@ export class AppsEngineService extends ServiceClassInternal implements IAppsEngi
});

this.onEvent('apps.added', async (appId: string): Promise<void> => {
// 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);
});

Expand Down Expand Up @@ -64,7 +71,16 @@ export class AppsEngineService extends ServiceClassInternal implements IAppsEngi
}
});

this.onEvent('apps.settingUpdated', async (appId: string, setting: ISetting): Promise<void> => {
this.onEvent('apps.settingUpdated', async (appId: string, setting: ISetting & { id: string }): Promise<void> => {
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;
Expand Down

0 comments on commit 4aa5794

Please sign in to comment.