-
Notifications
You must be signed in to change notification settings - Fork 13k
chore: optimize getRoomsWithSingleOwner to stop cursor iteration after assigning new owner #37292
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
Conversation
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
|
Looks like this PR is ready to merge! 🎉 |
|
WalkthroughThe loop in Changes
Sequence Diagram(s)sequenceDiagram
participant Runner as getRoomsWithSingleOwner
participant Cursor as Subscribers Cursor
participant Member as Subscriber (uid)
participant Room as RoomData
Note over Runner,Cursor: Iterate subscribers
Runner->>Cursor: fetch next member
Cursor->>Runner: member (uid)
alt member.uid == targetUser
Runner->>Runner: continue (skip)
else suitable member found
Runner->>Room: set newOwner, roomData.shouldChangeOwner = true
Runner-->>Cursor: break (stop iteration)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/meteor/app/lib/server/functions/getRoomsWithSingleOwner.ts (1)
57-60: Consider breaking immediately after assignment for optimal performance.The current implementation stops iteration after finding a new owner, which is a significant improvement. However, the break occurs on the next iteration, meaning one additional document is fetched from the cursor unnecessarily.
Apply this diff to break immediately after assigning the owner:
- if (roomData.shouldChangeOwner) { - break; - } - const newOwner = await Users.findOneActiveById(uid, { projection: { _id: 1 } }); if (!newOwner) { continue; } roomData.newOwner = uid; roomData.shouldChangeOwner = true; + break; }This eliminates even that one extra cursor fetch, fully optimizing the loop termination.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/meteor/app/lib/server/functions/getRoomsWithSingleOwner.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: CodeQL-Build
- GitHub Check: CodeQL-Build
🔇 Additional comments (1)
apps/meteor/app/lib/server/functions/getRoomsWithSingleOwner.ts (1)
54-56: LGTM! Simplified skip condition.Correctly skips only the subscriber being removed. The separation from the
shouldChangeOwnercheck improves clarity and sets up the early-exit optimization below.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #37292 +/- ##
===========================================
+ Coverage 66.88% 67.94% +1.05%
===========================================
Files 3411 3357 -54
Lines 117029 114906 -2123
Branches 21490 20765 -725
===========================================
- Hits 78274 78072 -202
+ Misses 36071 34149 -1922
- Partials 2684 2685 +1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
85f1258 to
c787054
Compare
Proposed changes (including videos or screenshots)
This PR improves the performance of the
getRoomsWithSingleOwnerfunction by ensuring the cursor iteration stops immediately after a new owner is assigned.Current Behavior
The existing implementation continues to iterate through all room members, even after assigning ownership to the oldest eligible member.
For rooms with many members, this leads to unnecessary processing and performance overhead.
Expected Behavior
Once a new owner is successfully assigned, the iteration should stop immediately.
Issue(s)
Steps to test or reproduce
Further comments
CORE-1504
Summary by CodeRabbit