Skip to content

Commit

Permalink
Revert "fix: update cached setting immediately at the time of updatin…
Browse files Browse the repository at this point in the history
…g the db (#32541)"

This reverts commit 06707d8.
  • Loading branch information
debdutdeb committed Jul 17, 2024
1 parent 3ffe4a2 commit a3711fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
5 changes: 0 additions & 5 deletions .changeset/cuddly-ravens-swim.md

This file was deleted.

22 changes: 8 additions & 14 deletions apps/meteor/app/settings/server/SettingsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,17 @@ export class SettingsRegistry {

const settingFromCodeOverwritten = overwriteSetting(settingFromCode);

const settingOverwrittenDefault = overrideSetting(settingFromCode);

const settingStored = this.store.getSetting(_id);

const settingStoredOverwritten = settingStored && overwriteSetting(settingStored);

const isOverwritten = settingFromCode !== settingFromCodeOverwritten || (settingStored && settingStored !== settingStoredOverwritten);

const updatedSettingAfterApplyingOverwrite = isOverwritten ? settingFromCodeOverwritten : settingOverwrittenDefault;

try {
validateSetting(settingFromCode._id, settingFromCode.type, settingFromCode.value);
} catch (e) {
IS_DEVELOPMENT && SystemLogger.error(`Invalid setting code ${_id}: ${(e as Error).message}`);
}

const isOverwritten = settingFromCode !== settingFromCodeOverwritten || (settingStored && settingStored !== settingStoredOverwritten);

const { _id: _, ...settingProps } = settingFromCodeOverwritten;

if (settingStored && !compareSettings(settingStored, settingFromCodeOverwritten)) {
Expand All @@ -171,9 +166,6 @@ export class SettingsRegistry {
})();

await this.saveUpdatedSetting(_id, updatedProps, removedKeys);

this.store.set(updatedSettingAfterApplyingOverwrite);

return;
}

Expand All @@ -183,8 +175,6 @@ export class SettingsRegistry {
const removedKeys = Object.keys(settingStored).filter((key) => !['_updatedAt'].includes(key) && !overwrittenKeys.includes(key));

await this.saveUpdatedSetting(_id, settingProps, removedKeys);

this.store.set(updatedSettingAfterApplyingOverwrite);
}
return;
}
Expand All @@ -198,9 +188,13 @@ export class SettingsRegistry {
return;
}

await this.model.insertOne(updatedSettingAfterApplyingOverwrite); // no need to emit unless we remove the oplog
const settingOverwrittenDefault = overrideSetting(settingFromCode);

const setting = isOverwritten ? settingFromCodeOverwritten : settingOverwrittenDefault;

await this.model.insertOne(setting); // no need to emit unless we remove the oplog

this.store.set(updatedSettingAfterApplyingOverwrite);
this.store.set(setting);
}

/*
Expand Down

0 comments on commit a3711fb

Please sign in to comment.