chore(migration): drop unique index on Read Receipts collection to im…#40308
chore(migration): drop unique index on Read Receipts collection to im…#40308DivyanshuVortex wants to merge 7 commits into
Conversation
…prove performance
|
|
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)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (1)**/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
🧠 Learnings (3)📓 Common learnings📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
WalkthroughRemoves a legacy commented compound index from the ReadReceipts model and adds migration v336 that attempts to drop the Changes
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.
🧹 Nitpick comments (1)
apps/meteor/server/startup/migrations/v336.ts (1)
9-13: Include the underlying error in the warning log.The current
catch {}discards the error entirely, so genuine failures (connectivity, permissions, etc.) are indistinguishable from the expected "index not found" case and the migration silently reports success. Capture the error and include it in the log so operators can diagnose unexpected failures.♻️ Proposed refactor
- try { - await ReadReceipts.col.dropIndex('roomId_1_userId_1_messageId_1'); - } catch { - console.warn('Error dropping index roomId_1_userId_1_messageId_1 from Read Receipts collection, it might have already been dropped.'); - } + try { + await ReadReceipts.col.dropIndex('roomId_1_userId_1_messageId_1'); + } catch (error) { + console.warn('Error dropping index roomId_1_userId_1_messageId_1 from Read Receipts collection, it might have already been dropped.', error); + }🤖 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 9 - 13, Update the catch block around the ReadReceipts.col.dropIndex call to capture the caught error and include it in the warning log so unexpected failures are visible; specifically, change the bare catch to capture the error (e.g., catch (err)) and pass that error (or err.message) into console.warn along with the existing descriptive text for ReadReceipts.col.dropIndex('roomId_1_userId_1_messageId_1') so operators can distinguish "index not found" from real failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/meteor/server/startup/migrations/v336.ts`:
- Around line 9-13: Update the catch block around the ReadReceipts.col.dropIndex
call to capture the caught error and include it in the warning log so unexpected
failures are visible; specifically, change the bare catch to capture the error
(e.g., catch (err)) and pass that error (or err.message) into console.warn along
with the existing descriptive text for
ReadReceipts.col.dropIndex('roomId_1_userId_1_messageId_1') so operators can
distinguish "index not found" from real failures.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c9d21145-a536-491e-9cf9-f2c202fab426
📒 Files selected for processing (2)
apps/meteor/ee/server/models/raw/ReadReceipts.tsapps/meteor/server/startup/migrations/v336.ts
💤 Files with no reviewable changes (1)
- apps/meteor/ee/server/models/raw/ReadReceipts.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/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.
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:58.834Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
📚 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
📚 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/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/v336.ts
|
@ggazzo , please have a look |
Proposed changes
This PR introduces migration
v336to safely drop the compound indexroomId_1_userId_1_messageId_1from theread_receiptscollection in existing databases.This PR cleans up the
read_receiptscode to remove the obsolete TODO and introduces the necessary database migration script to actively delete the deprecated index, reclaiming storage space and avoiding unnecessary write overhead.Issue :
#40235
Steps to test or reproduce
read_receiptscollection using:db.getCollection('read_receipts').createIndex({ roomId: 1, userId: 1, messageId: 1 }, { unique: true })336executes successfully.roomId_1_userId_1_messageId_1index no longer exists in theread_receiptscollection (db.getCollection('read_receipts').getIndexes()).Milestone : Migration of 9.0
Summary by CodeRabbit