Skip to content

chore: drop read receipts index#40292

Open
AYUSHSAHU2004 wants to merge 3 commits intoRocketChat:release-9.0.0from
AYUSHSAHU2004:chore/drop-read-receipts-index
Open

chore: drop read receipts index#40292
AYUSHSAHU2004 wants to merge 3 commits intoRocketChat:release-9.0.0from
AYUSHSAHU2004:chore/drop-read-receipts-index

Conversation

@AYUSHSAHU2004
Copy link
Copy Markdown

@AYUSHSAHU2004 AYUSHSAHU2004 commented Apr 24, 2026

This PR removes the read receipts index as it is no longer required.

Summary by CodeRabbit

  • Chores
    • Added a startup migration that removes a legacy unique index from the read receipts collection.
    • This cleanup reduces redundant metadata and may improve database storage and performance during subsequent operations.

@AYUSHSAHU2004 AYUSHSAHU2004 requested a review from a team as a code owner April 24, 2026 07:23
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Apr 24, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: 6f5462c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 38a97edd-45fd-4264-b4ee-e072b88625ae

📥 Commits

Reviewing files that changed from the base of the PR and between 80872ba and 6f5462c.

📒 Files selected for processing (1)
  • apps/meteor/server/startup/migrations/v336.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/server/startup/migrations/v336.ts

Walkthrough

Adds a new migration (v336) that runs at startup and attempts to drop a legacy compound index on the read_receipts collection with keys { roomId: 1, userId: 1, messageId: 1 }, ignoring "index not found" errors.

Changes

Cohort / File(s) Summary
Migrations initializer & new migration
apps/meteor/server/startup/migrations/index.ts, apps/meteor/server/startup/migrations/v336.ts
Imports the new v336 migration into the migrations initializer. v336 registers a migration that calls ReadReceipts.col.dropIndex(...) for the legacy compound index, catching and suppressing errors that indicate the index is missing (code === 27 or codeName === 'IndexNotFound').

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: chore

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'chore: drop read receipts index' accurately and clearly summarizes the main change—removing a legacy unique index from the read_receipts collection, which aligns with the changeset and PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/meteor/server/startup/migrations/v336.ts (1)

4-23: Refactor to use the idiomatic ReadReceipts.col.dropIndex() pattern with IndexNotFound handling.

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 name roomId_1_userId_1_messageId_1 and handle the IndexNotFound error (code 27) to ensure idempotency.

Additionally, indexes() returns entries where name is typed as string | 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

📥 Commits

Reviewing files that changed from the base of the PR and between 49422b7 and 11b2fa5.

📒 Files selected for processing (2)
  • apps/meteor/server/startup/migrations/index.ts
  • apps/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.ts
  • 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.
📚 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.ts
  • 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/index.ts
  • apps/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.

Comment thread apps/meteor/server/startup/migrations/v336.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant