diff --git a/.changeset/young-humans-stare.md b/.changeset/young-humans-stare.md new file mode 100644 index 0000000000000..c887f9479f673 --- /dev/null +++ b/.changeset/young-humans-stare.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/models': 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 8a1dae77dc76e..47ddb6a633f93 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 {