Skip to content

Commit e14f955

Browse files
authored
chore: optimize getRoomsWithSingleOwner to stop cursor iteration after assigning new owner (RocketChat#37292)
1 parent 9925505 commit e14f955

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

apps/meteor/app/lib/server/functions/getRoomsWithSingleOwner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function getSubscribedRoomsForUserWithDetails(
5151
u: { _id: uid },
5252
} of subscribersCursor) {
5353
// If we already changed the owner or this subscription is for the user we are removing, then don't try to give it ownership
54-
if (roomData.shouldChangeOwner || uid === userId) {
54+
if (uid === userId) {
5555
continue;
5656
}
5757
const newOwner = await Users.findOneActiveById(uid, { projection: { _id: 1 } });
@@ -61,6 +61,7 @@ export async function getSubscribedRoomsForUserWithDetails(
6161

6262
roomData.newOwner = uid;
6363
roomData.shouldChangeOwner = true;
64+
break;
6465
}
6566

6667
// If there's no subscriber available to be the new owner and it's not a public room, we can remove it.

0 commit comments

Comments
 (0)