chore: drop read receipts index#40292
chore: drop read receipts index#40292AYUSHSAHU2004 wants to merge 3 commits intoRocketChat:release-9.0.0from
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a new migration (v336) that runs at startup and attempts to drop a legacy compound index on the Changes
Sequence Diagram(s)sequenceDiagram
participant Init as MigrationsInitializer
participant Mig as Migration v336
participant DB as MongoDB (ReadReceipts)
Init->>Mig: import/register migration at startup
Init->>Mig: run migration v336.up()
Mig->>DB: ReadReceipts.col.indexes() / find index name
alt index exists
Mig->>DB: dropIndex(indexName)
DB-->>Mig: success
else index missing
DB-->>Mig: error (code 27 / IndexNotFound)
Mig--xDB: suppress error
end
Mig-->>Init: migration complete
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/meteor/server/startup/migrations/v336.ts (1)
4-23: Refactor to use the idiomaticReadReceipts.col.dropIndex()pattern withIndexNotFoundhandling.The current find-then-drop approach is more verbose than needed and diverges from the repo's established migration pattern (see
v323.ts). Drop the index by its MongoDB default nameroomId_1_userId_1_messageId_1and handle theIndexNotFounderror (code 27) to ensure idempotency.Additionally,
indexes()returns entries wherenameis typed asstring | undefined, so the current code relies on an implicit non-null assumption.♻️ Refactored to match v323.ts pattern
-import { addMigration } from '../../lib/migrations'; -import { getRawCollection } from '@rocket.chat/models'; - -addMigration({ - version: 336, - name: 'Drop legacy unique index from read_receipts', - async up() { - const collection = getRawCollection('read_receipts'); - - const indexes = await collection.indexes(); - - const targetIndex = indexes.find((idx) => { - return ( - idx.key?.roomId === 1 && - idx.key?.userId === 1 && - idx.key?.messageId === 1 - ); - }); - - if (targetIndex) { - await collection.dropIndex(targetIndex.name); - } - }, -}); +import { ReadReceipts } from '@rocket.chat/models'; + +import { addMigration } from '../../lib/migrations'; + +addMigration({ + version: 336, + name: 'Drop legacy unique index from read_receipts', + async up() { + try { + await ReadReceipts.col.dropIndex('roomId_1_userId_1_messageId_1'); + } catch (e: any) { + if (e?.code !== 27 && e?.codeName !== 'IndexNotFound') { + throw e; + } + } + }, +});🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/meteor/server/startup/migrations/v336.ts` around lines 4 - 23, Replace the find-then-drop logic in migration v336 with the repository's idiomatic call to ReadReceipts.col.dropIndex using the default index name "roomId_1_userId_1_messageId_1"; call ReadReceipts.col.dropIndex("roomId_1_userId_1_messageId_1") inside the up() of addMigration and catch the MongoDB IndexNotFound case (error code 27) to ignore it (ensuring idempotency) while rethrowing other errors, rather than inspecting indexes() and assuming index.name is non-null.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/meteor/server/startup/migrations/v336.ts`:
- Around line 1-2: Import ReadReceipts from '@rocket.chat/models' instead of
getRawCollection and update uses of getRawCollection('read_receipts') to use
ReadReceipts.col; specifically replace the import symbol getRawCollection with
ReadReceipts and change any call sites that reference
getRawCollection('read_receipts') to use ReadReceipts.col (e.g.,
ReadReceipts.col.dropIndex(...) or ReadReceipts.col.createIndex(...)) so the
migration uses the typed model collection.
---
Nitpick comments:
In `@apps/meteor/server/startup/migrations/v336.ts`:
- Around line 4-23: Replace the find-then-drop logic in migration v336 with the
repository's idiomatic call to ReadReceipts.col.dropIndex using the default
index name "roomId_1_userId_1_messageId_1"; call
ReadReceipts.col.dropIndex("roomId_1_userId_1_messageId_1") inside the up() of
addMigration and catch the MongoDB IndexNotFound case (error code 27) to ignore
it (ensuring idempotency) while rethrowing other errors, rather than inspecting
indexes() and assuming index.name is non-null.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 267b73b9-cefb-441c-b481-69e73334025b
📒 Files selected for processing (2)
apps/meteor/server/startup/migrations/index.tsapps/meteor/server/startup/migrations/v336.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/server/startup/migrations/index.tsapps/meteor/server/startup/migrations/v336.ts
🧠 Learnings (6)
📓 Common learnings
Learnt from: rodrigok
Repo: RocketChat/Rocket.Chat PR: 38623
File: apps/meteor/app/lib/server/functions/cleanRoomHistory.ts:146-149
Timestamp: 2026-04-18T12:32:53.425Z
Learning: In `apps/meteor/app/lib/server/functions/cleanRoomHistory.ts` (PR `#38623`), the read-receipt cleanup (both `ReadReceipts.removeByMessageIds` and `ReadReceiptsArchive.removeByMessageIds`) is intentionally only performed in the limited prune path (`limit && selectedMessageIds`). The unlimited/delete-all path (`limit === 0`) deliberately skips cleaning up orphaned read receipts in both hot and cold storage — this is by design. Do not flag this as a bug or missing cleanup in future reviews.
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/server/startup/migrations/index.tsapps/meteor/server/startup/migrations/v336.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/server/startup/migrations/index.tsapps/meteor/server/startup/migrations/v336.ts
📚 Learning: 2026-04-18T12:32:53.425Z
Learnt from: rodrigok
Repo: RocketChat/Rocket.Chat PR: 38623
File: apps/meteor/app/lib/server/functions/cleanRoomHistory.ts:146-149
Timestamp: 2026-04-18T12:32:53.425Z
Learning: In `apps/meteor/app/lib/server/functions/cleanRoomHistory.ts` (PR `#38623`), the read-receipt cleanup (both `ReadReceipts.removeByMessageIds` and `ReadReceiptsArchive.removeByMessageIds`) is intentionally only performed in the limited prune path (`limit && selectedMessageIds`). The unlimited/delete-all path (`limit === 0`) deliberately skips cleaning up orphaned read receipts in both hot and cold storage — this is by design. Do not flag this as a bug or missing cleanup in future reviews.
Applied to files:
apps/meteor/server/startup/migrations/v336.ts
📚 Learning: 2026-03-11T22:04:20.529Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 39545
File: apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts:59-61
Timestamp: 2026-03-11T22:04:20.529Z
Learning: In `apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts`, the `msg.u._id === uid` early-return in the `streamNewMessage` handler is intentional: the "New messages" indicator is designed to notify about messages from other users only. Self-sent messages — including those sent from a different session/device — are always skipped, by design. Do not flag this as a multi-session regression.
Applied to files:
apps/meteor/server/startup/migrations/v336.ts
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.
Applied to files:
apps/meteor/server/startup/migrations/v336.ts
🔇 Additional comments (1)
apps/meteor/server/startup/migrations/index.ts (1)
44-44: LGTM — v336 wired in, following the existing ordering convention.
This PR removes the read receipts index as it is no longer required.
Summary by CodeRabbit