diff --git a/.changeset/young-humans-stare.md b/.changeset/young-humans-stare.md new file mode 100644 index 00000000000..f9d113d947d --- /dev/null +++ b/.changeset/young-humans-stare.md @@ -0,0 +1,6 @@ +--- +'@rocket.chat/models': patch +'@rocket.chat/meteor': patch +--- + +Adds automatic cleanup of statistics collection with 1-year retention via TTL index. diff --git a/packages/models/src/models/Statistics.ts b/packages/models/src/models/Statistics.ts index 8a1dae77dc7..47ddb6a633f 100644 --- a/packages/models/src/models/Statistics.ts +++ b/packages/models/src/models/Statistics.ts @@ -10,7 +10,10 @@ export class StatisticsRaw extends BaseRaw implements IStatisticsModel { } protected override modelIndexes(): IndexDescription[] { - return [{ key: { createdAt: -1 } }]; + return [ + { key: { createdAt: -1 } }, + { key: { createdAt: 1 }, expireAfterSeconds: 365 * 24 * 60 * 60 }, // expire after 1 year + ]; } async findLast(): Promise {