Skip to content

Commit

Permalink
fix: Retention Policy cached settings not updated during upgrade proc…
Browse files Browse the repository at this point in the history
…edure (#33237)
  • Loading branch information
gabriellsh authored Sep 12, 2024
1 parent a45b88c commit 06256cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-swans-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fixed retention policy max age settings not being respected after upgrade
14 changes: 12 additions & 2 deletions apps/meteor/server/startup/migrations/xrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Settings } from '@rocket.chat/models';
import type { UpdateResult } from 'mongodb';

import { upsertPermissions } from '../../../app/authorization/server/functions/upsertPermissions';
import { settings } from '../../../app/settings/server';
import { migrateDatabase, onServerVersionChange } from '../../lib/migrations';
import { ensureCloudWorkspaceRegistered } from '../cloudRegistration';

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

const newValue = convertDaysToMs(Number(value));

promises.push(
Settings.updateOne(
{
_id: maxAgeSettingMap.get(_id),
},
{
$set: {
value: convertDaysToMs(Number(value)),
value: newValue,
},
},
),
);

const currentCache = settings.getSetting(newSettingId);
if (!currentCache) {
return;
}
settings.set({ ...currentCache, value: newValue });
});

await Promise.all(promises);
Expand Down

0 comments on commit 06256cc

Please sign in to comment.