Skip to content

chore: avoid fetching data just for counting#41313

Open
sampaiodiego wants to merge 2 commits into
developfrom
chore-avoid-fetching-data-for-counts
Open

chore: avoid fetching data just for counting#41313
sampaiodiego wants to merge 2 commits into
developfrom
chore-avoid-fetching-data-for-counts

Conversation

@sampaiodiego

@sampaiodiego sampaiodiego commented Jul 10, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Issue(s)

Follow up of #41207

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Performance Improvements
    • Improved response times and resource usage for message delivery, permission updates, custom sounds, custom emoji, user statuses, and live chat room lookups.
    • Reduced unnecessary data retrieval during SAML logout processing and message cleanup.
  • Statistics
    • Improved integration statistics processing while preserving existing reporting results.
  • Reliability
    • Strengthened validation for referenced permissions and roles, with clearer handling of invalid entries.

@dionisio-bot

dionisio-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 619b5a8

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

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 13121548-7c70-45d8-bae5-eb4edbba0b6b

📥 Commits

Reviewing files that changed from the base of the PR and between b634242 and 619b5a8.

📒 Files selected for processing (19)
  • apps/meteor/app/user-status/server/methods/insertOrUpdateUserStatus.ts
  • apps/meteor/server/api/v1/omnichannel/message.ts
  • apps/meteor/server/api/v1/permissions.ts
  • apps/meteor/server/lib/media/custom-sounds/lib/insertOrUpdateSound.ts
  • apps/meteor/server/lib/media/emoji-custom/lib/insertOrUpdateEmoji.ts
  • apps/meteor/server/lib/saml/lib/SAML.ts
  • apps/meteor/server/lib/statistics/lib/statistics.ts
  • packages/model-typings/src/models/IBaseModel.ts
  • packages/model-typings/src/models/ICustomSoundsModel.ts
  • packages/model-typings/src/models/ICustomUserStatusModel.ts
  • packages/model-typings/src/models/IEmojiCustomModel.ts
  • packages/model-typings/src/models/IIntegrationsModel.ts
  • packages/model-typings/src/models/ILivechatRoomsModel.ts
  • packages/models/src/models/CustomSounds.ts
  • packages/models/src/models/CustomUserStatus.ts
  • packages/models/src/models/EmojiCustom.ts
  • packages/models/src/models/Integrations.ts
  • packages/models/src/models/LivechatRooms.ts
  • packages/models/src/models/Messages.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (5)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🧰 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/api/v1/permissions.ts
  • packages/models/src/models/LivechatRooms.ts
  • apps/meteor/server/lib/media/custom-sounds/lib/insertOrUpdateSound.ts
  • packages/model-typings/src/models/ICustomUserStatusModel.ts
  • packages/models/src/models/CustomUserStatus.ts
  • packages/model-typings/src/models/IBaseModel.ts
  • apps/meteor/app/user-status/server/methods/insertOrUpdateUserStatus.ts
  • packages/model-typings/src/models/IEmojiCustomModel.ts
  • packages/models/src/models/CustomSounds.ts
  • packages/model-typings/src/models/ICustomSoundsModel.ts
  • packages/models/src/models/Integrations.ts
  • apps/meteor/server/lib/media/emoji-custom/lib/insertOrUpdateEmoji.ts
  • packages/model-typings/src/models/ILivechatRoomsModel.ts
  • apps/meteor/server/lib/saml/lib/SAML.ts
  • apps/meteor/server/lib/statistics/lib/statistics.ts
  • packages/models/src/models/EmojiCustom.ts
  • apps/meteor/server/api/v1/omnichannel/message.ts
  • packages/model-typings/src/models/IIntegrationsModel.ts
  • packages/models/src/models/Messages.ts
🧠 Learnings (3)
📚 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/api/v1/permissions.ts
  • packages/models/src/models/LivechatRooms.ts
  • apps/meteor/server/lib/media/custom-sounds/lib/insertOrUpdateSound.ts
  • packages/model-typings/src/models/ICustomUserStatusModel.ts
  • packages/models/src/models/CustomUserStatus.ts
  • packages/model-typings/src/models/IBaseModel.ts
  • apps/meteor/app/user-status/server/methods/insertOrUpdateUserStatus.ts
  • packages/model-typings/src/models/IEmojiCustomModel.ts
  • packages/models/src/models/CustomSounds.ts
  • packages/model-typings/src/models/ICustomSoundsModel.ts
  • packages/models/src/models/Integrations.ts
  • apps/meteor/server/lib/media/emoji-custom/lib/insertOrUpdateEmoji.ts
  • packages/model-typings/src/models/ILivechatRoomsModel.ts
  • apps/meteor/server/lib/saml/lib/SAML.ts
  • apps/meteor/server/lib/statistics/lib/statistics.ts
  • packages/models/src/models/EmojiCustom.ts
  • apps/meteor/server/api/v1/omnichannel/message.ts
  • packages/model-typings/src/models/IIntegrationsModel.ts
  • packages/models/src/models/Messages.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/api/v1/permissions.ts
  • packages/models/src/models/LivechatRooms.ts
  • apps/meteor/server/lib/media/custom-sounds/lib/insertOrUpdateSound.ts
  • packages/model-typings/src/models/ICustomUserStatusModel.ts
  • packages/models/src/models/CustomUserStatus.ts
  • packages/model-typings/src/models/IBaseModel.ts
  • apps/meteor/app/user-status/server/methods/insertOrUpdateUserStatus.ts
  • packages/model-typings/src/models/IEmojiCustomModel.ts
  • packages/models/src/models/CustomSounds.ts
  • packages/model-typings/src/models/ICustomSoundsModel.ts
  • packages/models/src/models/Integrations.ts
  • apps/meteor/server/lib/media/emoji-custom/lib/insertOrUpdateEmoji.ts
  • packages/model-typings/src/models/ILivechatRoomsModel.ts
  • apps/meteor/server/lib/saml/lib/SAML.ts
  • apps/meteor/server/lib/statistics/lib/statistics.ts
  • packages/models/src/models/EmojiCustom.ts
  • apps/meteor/server/api/v1/omnichannel/message.ts
  • packages/model-typings/src/models/IIntegrationsModel.ts
  • packages/models/src/models/Messages.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/server/api/v1/permissions.ts
  • packages/models/src/models/LivechatRooms.ts
  • apps/meteor/server/lib/media/custom-sounds/lib/insertOrUpdateSound.ts
  • packages/model-typings/src/models/ICustomUserStatusModel.ts
  • packages/models/src/models/CustomUserStatus.ts
  • packages/model-typings/src/models/IBaseModel.ts
  • apps/meteor/app/user-status/server/methods/insertOrUpdateUserStatus.ts
  • packages/model-typings/src/models/IEmojiCustomModel.ts
  • packages/models/src/models/CustomSounds.ts
  • packages/model-typings/src/models/ICustomSoundsModel.ts
  • packages/models/src/models/Integrations.ts
  • apps/meteor/server/lib/media/emoji-custom/lib/insertOrUpdateEmoji.ts
  • packages/model-typings/src/models/ILivechatRoomsModel.ts
  • apps/meteor/server/lib/saml/lib/SAML.ts
  • apps/meteor/server/lib/statistics/lib/statistics.ts
  • packages/models/src/models/EmojiCustom.ts
  • apps/meteor/server/api/v1/omnichannel/message.ts
  • packages/model-typings/src/models/IIntegrationsModel.ts
  • packages/models/src/models/Messages.ts
🔇 Additional comments (17)
packages/model-typings/src/models/IIntegrationsModel.ts (1)

2-14: LGTM!

Also applies to: 28-28

packages/models/src/models/Integrations.ts (1)

2-3: LGTM!

Also applies to: 76-116

apps/meteor/server/lib/statistics/lib/statistics.ts (1)

450-452: LGTM!

packages/model-typings/src/models/IBaseModel.ts (1)

7-7: LGTM!

Also applies to: 132-132

packages/model-typings/src/models/ICustomSoundsModel.ts (1)

8-8: LGTM!

packages/model-typings/src/models/ICustomUserStatusModel.ts (1)

9-9: LGTM!

packages/model-typings/src/models/IEmojiCustomModel.ts (1)

8-8: LGTM!

packages/models/src/models/CustomSounds.ts (1)

26-34: LGTM!

packages/models/src/models/CustomUserStatus.ts (1)

24-32: LGTM!

packages/models/src/models/EmojiCustom.ts (1)

3-3: LGTM!

Also applies to: 31-39

packages/model-typings/src/models/ILivechatRoomsModel.ts (1)

176-180: LGTM!

packages/models/src/models/LivechatRooms.ts (1)

1899-1904: LGTM!

apps/meteor/app/user-status/server/methods/insertOrUpdateUserStatus.ts (1)

55-59: LGTM!

apps/meteor/server/api/v1/omnichannel/message.ts (1)

260-261: LGTM!

apps/meteor/server/api/v1/permissions.ts (1)

183-193: LGTM!

packages/models/src/models/Messages.ts (1)

1399-1406: LGTM!

apps/meteor/server/lib/media/emoji-custom/lib/insertOrUpdateEmoji.ts (1)

71-78: 🎯 Functional Correctness

findOneByNamesOrAliases matches the model signature; no change is needed.

			> Likely an incorrect or invalid review comment.

Walkthrough

The pull request replaces several full-result database queries with targeted lookups, bounded projections, count operations, and aggregation. It adds model interfaces and implementations for single-record lookups and integration statistics, then updates affected application flows.

Changes

Database Query Optimization

Layer / File(s) Summary
Single-record lookup APIs
packages/model-typings/src/models/ICustomSoundsModel.ts, packages/model-typings/src/models/ICustomUserStatusModel.ts, packages/model-typings/src/models/IEmojiCustomModel.ts, packages/model-typings/src/models/ILivechatRoomsModel.ts, packages/models/src/models/CustomSounds.ts, packages/models/src/models/CustomUserStatus.ts, packages/models/src/models/EmojiCustom.ts, packages/models/src/models/LivechatRooms.ts, apps/meteor/app/user-status/..., apps/meteor/server/lib/media/..., apps/meteor/server/api/v1/omnichannel/message.ts
Single-record model methods and projections replace materialized name, alias, status, and room lookups.
Count-based validation
packages/model-typings/src/models/IBaseModel.ts, apps/meteor/server/api/v1/permissions.ts, packages/models/src/models/Messages.ts
Permission, role, and message matching checks use countDocuments, including optional count options and preserved limits.
Bounded SAML lookups
apps/meteor/server/lib/saml/lib/SAML.ts
SAML logout lookups project _id and limit results to two while retaining missing, unique, and ambiguous result handling.
Aggregated integration statistics
packages/model-typings/src/models/IIntegrationsModel.ts, packages/models/src/models/Integrations.ts, apps/meteor/server/lib/statistics/lib/statistics.ts
A typed getStatistics aggregation computes integration totals and status counters for the statistics response.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested labels: type: chore

Suggested reviewers: tassoevan, kevl ehman

🚥 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 title clearly summarizes the main change: replacing fetch-heavy count logic with count-based checks.
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.

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.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.16%. Comparing base (b634242) to head (619b5a8).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41313      +/-   ##
===========================================
- Coverage    68.27%   68.16%   -0.11%     
===========================================
  Files         3968     3968              
  Lines       154740   154725      -15     
  Branches     27847    27818      -29     
===========================================
- Hits        105652   105476     -176     
- Misses       44294    44452     +158     
- Partials      4794     4797       +3     
Flag Coverage Δ
e2e 59.23% <ø> (-0.15%) ⬇️
e2e-api 44.00% <69.23%> (-0.37%) ⬇️
unit 70.58% <0.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sampaiodiego sampaiodiego force-pushed the chore-avoid-fetching-data-for-counts branch from 5eb8db5 to 4348969 Compare July 14, 2026 19:09
@sampaiodiego sampaiodiego marked this pull request as ready for review July 14, 2026 20:16
@sampaiodiego sampaiodiego requested review from a team as code owners July 14, 2026 20:16

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 19 files

Re-trigger cubic

@sampaiodiego sampaiodiego added this to the 8.7.0 milestone Jul 14, 2026
@sampaiodiego sampaiodiego added the stat: QA assured Means it has been tested and approved by a company insider label Jul 14, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: chore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants