From f358e57019d5915dbf9b8427222907eb86e8d81f Mon Sep 17 00:00:00 2001 From: Ricardo Garim Date: Mon, 9 Feb 2026 10:55:48 -0300 Subject: [PATCH 1/2] fix: add TTL index to statistics collection for automatic cleanup --- packages/models/src/models/Statistics.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 { From 073dfa8bbeae58526a95d53330872cdad578439b Mon Sep 17 00:00:00 2001 From: Ricardo Garim Date: Mon, 9 Feb 2026 10:55:52 -0300 Subject: [PATCH 2/2] chore: add changeset --- .changeset/young-humans-stare.md | 5 +++++ 1 file changed, 5 insertions(+) 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 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.