[FIX] No warning message is sent when user is removed from a team's main channel#21949
[FIX] No warning message is sent when user is removed from a team's main channel#21949sampaiodiego merged 3 commits intodevelopfrom
Conversation
server/services/team/service.ts
Outdated
|
|
||
| await this.unsubscribeFromMain(team.roomId, member.userId); | ||
| const removedUser = await this.Users.findOneById(member.userId, { projection: { _id: 1, username: 1 } }); | ||
| const byUser = uid !== member.userId ? await this.Users.findOneById(uid, { projection: { _id: 1, username: 1 } }) : undefined; |
There was a problem hiding this comment.
my only issue with this is that if a user is removing some other users, for every user being removed it will execute the same find for uid..
to avoid this I'd suggest to do a find for uid outside the loop and use it when needed.
There was a problem hiding this comment.
Following this line, it would be better to extract all the userIds before the loop, and then doing a find for all, instead of one by one 🤔 (then inside of this loop you can use arr.find)
There was a problem hiding this comment.
Great, I've just applied both changes (the find for uid is now performed only once, and I grouped the findOneById for each userId in a single find).
d3bafc2
server/services/team/service.ts
Outdated
| } | ||
|
|
||
| const membersIds = members.map((m) => m.userId); | ||
| const usersToRemove = await this.Users.find({ _id: { $in: membersIds } }, { projection: { _id: 1, username: 1 } }).toArray(); |
There was a problem hiding this comment.
the new changes are looking good, it is definitely better finding all members at once 👏
we just need to avoid using custom queries, so in this case I'd recommend using this.Users.findByIds.. looks like it doesn't exists, so you'd to create it.. 😉
Proposed changes (including videos or screenshots)
usersCountfield in the team's main room when a user is removed from the team (usersCountis now decreased by 1).Issue(s)
Task - ClickUp (no warning messages are sent)
Task - ClickUp (
usersCountfield is decreased by 2)Steps to test or reproduce
Create a new team and insert/remove a member. When a user is removed or leaves a team, its main channel's
usersCountfield will be decreased by 1 and a warning message will be sent.Further comments
Fixes #21901 (includes its changes)