Skip to content

Commit

Permalink
fix: Retention policy cron max age settings reactivity (#33049)
Browse files Browse the repository at this point in the history
Co-authored-by: gabriellsh <[email protected]>
  • Loading branch information
dionisio-bot[bot] and gabriellsh authored Aug 15, 2024
1 parent b3ac6d9 commit 3ca62ee
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions apps/meteor/app/retention-policy/server/cronPruneMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import { getCronAdvancedTimerFromPrecisionSetting } from '../../../lib/getCronAd
import { cleanRoomHistory } from '../../lib/server/functions/cleanRoomHistory';
import { settings } from '../../settings/server';

const maxTimes = {
c: 0,
p: 0,
d: 0,
type RetentionRoomTypes = 'c' | 'p' | 'd';

const getMaxAgeSettingIdByRoomType = (type: RetentionRoomTypes) => {
switch (type) {
case 'c':
return settings.get<number>('RetentionPolicy_TTL_Channels');
case 'p':
return settings.get<number>('RetentionPolicy_TTL_Groups');
case 'd':
return settings.get<number>('RetentionPolicy_TTL_DMs');
}
};

let types: (keyof typeof maxTimes)[] = [];
let types: RetentionRoomTypes[] = [];

const oldest = new Date('0001-01-01T00:00:00Z');

Expand All @@ -29,7 +36,7 @@ async function job(): Promise<void> {

// get all rooms with default values
for await (const type of types) {
const maxAge = maxTimes[type] || 0;
const maxAge = getMaxAgeSettingIdByRoomType(type) || 0;
const latest = new Date(now.getTime() - maxAge);

const rooms = await Rooms.find(
Expand Down Expand Up @@ -95,9 +102,6 @@ settings.watchMultiple(
'RetentionPolicy_AppliesToChannels',
'RetentionPolicy_AppliesToGroups',
'RetentionPolicy_AppliesToDMs',
'RetentionPolicy_TTL_Channels',
'RetentionPolicy_TTL_Groups',
'RetentionPolicy_TTL_DMs',
'RetentionPolicy_Advanced_Precision',
'RetentionPolicy_Advanced_Precision_Cron',
'RetentionPolicy_Precision',
Expand All @@ -120,10 +124,6 @@ settings.watchMultiple(
types.push('d');
}

maxTimes.c = settings.get<number>('RetentionPolicy_TTL_Channels');
maxTimes.p = settings.get<number>('RetentionPolicy_TTL_Groups');
maxTimes.d = settings.get<number>('RetentionPolicy_TTL_DMs');

const precision =
(settings.get<boolean>('RetentionPolicy_Advanced_Precision') && settings.get<string>('RetentionPolicy_Advanced_Precision_Cron')) ||
getCronAdvancedTimerFromPrecisionSetting(settings.get('RetentionPolicy_Precision'));
Expand Down

0 comments on commit 3ca62ee

Please sign in to comment.