-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix: unify statistics indexes with TTL expiration and add migration #38572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ricardogarim
wants to merge
4
commits into
develop
Choose a base branch
from
fix/statistics-index-migration
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+28
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f358e57
fix: add TTL index to statistics collection for automatic cleanup
ricardogarim 073dfa8
chore: add changeset
ricardogarim 6df9fef
fix: unify statistics indexes with TTL expiration and add migration
ricardogarim d57f8cb
chore: add changeset
ricardogarim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/models': patch | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Adds migration to remove redundant statistics index after TTL index consolidation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rocket.chat/models': patch | ||
| --- | ||
|
|
||
| Adds automatic cleanup of statistics collection with 1-year retention via TTL index. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,5 +41,6 @@ import './v332'; | |
| import './v333'; | ||
| import './v334'; | ||
| import './v335'; | ||
| import './v336'; | ||
|
|
||
| export * from './xrun'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Statistics } from '@rocket.chat/models'; | ||
|
|
||
| import { addMigration } from '../../lib/migrations'; | ||
|
|
||
| addMigration({ | ||
| version: 336, | ||
| name: 'Remove redundant statistics createdAt descending index', | ||
| async up() { | ||
| try { | ||
| await Statistics.col.dropIndex('createdAt_-1'); | ||
| } catch { | ||
| // Index might not exist on fresh installations | ||
| } | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 2852
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 518
🌐 Web query:
MongoDB error code 27 IndexNotFound official documentation💡 Result:
MongoDB error code
27=IndexNotFoundin the official MongoDB Server documentation under Reference → Error Codes. (mongodb.com)Citations:
Catch block swallows all errors, not just "index not found".
The empty
catchwill silently ignore any error (e.g., authentication failures, network issues), not just the expectedIndexNotFound. The codebase already establishes the proper pattern in v323.ts: check for MongoDB error code 27 and re-throw unexpected errors. Match that pattern here.Proposed fix
try { await Statistics.col.dropIndex('createdAt_-1'); - } catch { - // Index might not exist on fresh installations + } catch (e: any) { + if (e?.code !== 27 && e?.codeName !== 'IndexNotFound') { + throw e; + } }📝 Committable suggestion
🤖 Prompt for AI Agents