fix: add TTL index to statistics collection for automatic cleanup (#38568)

pull/32703/head
Ricardo Garim 1 week ago committed by GitHub
parent 42151e26f4
commit 123aebec2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      .changeset/young-humans-stare.md
  2. 5
      packages/models/src/models/Statistics.ts

@ -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.

@ -10,7 +10,10 @@ export class StatisticsRaw extends BaseRaw<IStats> 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<IStats> {

Loading…
Cancel
Save