From 123aebec2caa74b17d2b5dcbd2a2db2e687cf3ac Mon Sep 17 00:00:00 2001 From: Ricardo Garim Date: Wed, 18 Feb 2026 19:24:41 -0300 Subject: [PATCH] fix: add TTL index to statistics collection for automatic cleanup (#38568) --- .changeset/young-humans-stare.md | 6 ++++++ packages/models/src/models/Statistics.ts | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/young-humans-stare.md 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 {