From a68e2c688bc4e64bd6d97dd70a4c1ed6770be999 Mon Sep 17 00:00:00 2001 From: Debdut Chakraborty Date: Mon, 3 Jun 2024 09:51:05 +0530 Subject: [PATCH 1/2] update cache when inserting setting into model, don't wait for changestream --- .../app/settings/server/SettingsRegistry.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/meteor/app/settings/server/SettingsRegistry.ts b/apps/meteor/app/settings/server/SettingsRegistry.ts index 5783e2946dc1..443e38ce5d63 100644 --- a/apps/meteor/app/settings/server/SettingsRegistry.ts +++ b/apps/meteor/app/settings/server/SettingsRegistry.ts @@ -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)) { @@ -166,6 +171,9 @@ export class SettingsRegistry { })(); await this.saveUpdatedSetting(_id, updatedProps, removedKeys); + + this.store.set(updatedSettingAfterApplyingOverwrite); + return; } @@ -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; } @@ -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); } /* From b69f1c441db9b6d2ffe5cd60c397f8da1daec356 Mon Sep 17 00:00:00 2001 From: Debdut Chakraborty Date: Thu, 27 Jun 2024 22:25:55 +0530 Subject: [PATCH 2/2] add changeset --- .changeset/cuddly-ravens-swim.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cuddly-ravens-swim.md diff --git a/.changeset/cuddly-ravens-swim.md b/.changeset/cuddly-ravens-swim.md new file mode 100644 index 000000000000..5774ef48202d --- /dev/null +++ b/.changeset/cuddly-ravens-swim.md @@ -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.