Skip to content

Commit 02b3e38

Browse files
authored
fix: Retention Policy cached settings not updated during upgrade procedure (#33237)
1 parent ed7398d commit 02b3e38

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

.changeset/pink-swans-teach.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
fixed retention policy max age settings not being respected after upgrade

apps/meteor/server/startup/migrations/xrun.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Settings } from '@rocket.chat/models';
22
import type { UpdateResult } from 'mongodb';
33

44
import { upsertPermissions } from '../../../app/authorization/server/functions/upsertPermissions';
5+
import { settings } from '../../../app/settings/server';
56
import { migrateDatabase, onServerVersionChange } from '../../lib/migrations';
67
import { ensureCloudWorkspaceRegistered } from '../cloudRegistration';
78

@@ -23,22 +24,31 @@ const moveRetentionSetting = async () => {
2324
{ _id: { $in: Array.from(maxAgeSettingMap.keys()) }, value: { $ne: -1 } },
2425
{ projection: { _id: 1, value: 1 } },
2526
).forEach(({ _id, value }) => {
26-
if (!maxAgeSettingMap.has(_id)) {
27+
const newSettingId = maxAgeSettingMap.get(_id);
28+
if (!newSettingId) {
2729
throw new Error(`moveRetentionSetting - Setting ${_id} equivalent does not exist`);
2830
}
2931

32+
const newValue = convertDaysToMs(Number(value));
33+
3034
promises.push(
3135
Settings.updateOne(
3236
{
3337
_id: maxAgeSettingMap.get(_id),
3438
},
3539
{
3640
$set: {
37-
value: convertDaysToMs(Number(value)),
41+
value: newValue,
3842
},
3943
},
4044
),
4145
);
46+
47+
const currentCache = settings.getSetting(newSettingId);
48+
if (!currentCache) {
49+
return;
50+
}
51+
settings.set({ ...currentCache, value: newValue });
4252
});
4353

4454
await Promise.all(promises);

0 commit comments

Comments
 (0)