Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update cached setting immediately at the time of updating the db #32541

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cuddly-ravens-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed an issue where adding `OVERWRITE_SETTING_` for any setting wasn't immediately taking effect sometimes, and needed a server restart to reflect.
22 changes: 14 additions & 8 deletions apps/meteor/app/settings/server/SettingsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,22 @@ 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 @@ -166,6 +171,9 @@ export class SettingsRegistry {
})();

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

this.store.set(updatedSettingAfterApplyingOverwrite);

return;
}

Expand All @@ -175,6 +183,8 @@ 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 @@ -188,13 +198,9 @@ export class SettingsRegistry {
return;
}

const settingOverwrittenDefault = overrideSetting(settingFromCode);

const setting = isOverwritten ? settingFromCodeOverwritten : settingOverwrittenDefault;

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

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

/*
Expand Down
Loading