Skip to content
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

feat: add endpoint rooms.membersOrderedByRole #34153

Conversation

abhinavkrin
Copy link
Member

@abhinavkrin abhinavkrin commented Dec 10, 2024

Proposed changes (including videos or screenshots)

Adds groups.membersOrderedByRole and channels.membersOrderedByRole endpoints to retrieve members of groups and channels sorted according to their respective role in the room.
This will help in grouping of users according to their roles in the room like below.
image

The endpoint works similar as groups.members and channels.members, but accepts an optional rolesOrder[] param which can be used for defining roles order while sorting. The index of the role will signify its priority. By default, owner > moderator > rest of members.

The endpoint works similar as groups.members and channels.members, but sorts the members according to their role in the room. Owners > moderators > all other members. This can be reversed using sort={"rolePriority":-1}.

The changes introduces an additional field roomRolePriorities to user collection. It will store the roomId and rolePriority score mapping which will be helpful in bringing down the sort time when there are a large number of users in a room.

This PR also adds a migration to assign the roomRolePriority to already existing room members
I have adopted a soft migration approach, as we only include migrations during breaking changes. In the endpoint, we first check whether the role priorities for the room have already been created. If not, we proceed to create them. For subsequent calls, this process is skipped.

I conducted performance testing using a room with 30,000 owners and moderators and a total of 100,000 members. The first call took approximately ~1 second, while subsequent calls were as fast as the channels.members endpoint. In most practical cases, where room sizes are smaller, the response time is significantly shorter.

A sample request

curl --location 'http://localhost:3000/api/v1/rooms.membersOrderedByRole?roomName=general' \
--header 'X-Auth-Token: aeqK4p8Z8a-FQy8HiI0MIO3zcg4aHZX2vy6AHSpdvoi' \
--header 'X-User-Id: u29m4aQNjZujdE4r5' \
--data ''

Issue(s)

Steps to test or reproduce

Further comments

CORE-846

Copy link
Contributor

dionisio-bot bot commented Dec 10, 2024

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

Copy link

changeset-bot bot commented Dec 10, 2024

🦋 Changeset detected

Latest commit: dbe0674

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 37 packages
Name Type
@rocket.chat/i18n Minor
@rocket.chat/meteor Minor
@rocket.chat/rest-typings Minor
@rocket.chat/mock-providers Patch
@rocket.chat/ui-contexts Major
@rocket.chat/web-ui-registration Major
@rocket.chat/api-client Patch
@rocket.chat/core-services Patch
@rocket.chat/ddp-client Patch
@rocket.chat/models Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/fuselage-ui-kit Major
@rocket.chat/ui-client Major
@rocket.chat/ui-voip Major
@rocket.chat/uikit-playground Patch
@rocket.chat/gazzodown Major
@rocket.chat/livechat Patch
@rocket.chat/ui-avatar Major
@rocket.chat/ui-video-conf Major
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/network-broker Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/core-typings Minor
@rocket.chat/apps Patch
@rocket.chat/freeswitch Patch
@rocket.chat/model-typings Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch

Not sure what this means? Click here to learn what changesets are.

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

@abhinavkrin abhinavkrin added this to the 7.2.0 milestone Dec 10, 2024
@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch from 4a3be37 to aa02c7a Compare December 10, 2024 12:55
Copy link
Contributor

github-actions bot commented Dec 10, 2024

PR Preview Action v1.6.0

🚀 View preview at
https://RocketChat.github.io/Rocket.Chat/pr-preview/pr-34153/

Built to branch gh-pages at 2025-01-17 20:20 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.18%. Comparing base (3c237b2) to head (dbe0674).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #34153      +/-   ##
===========================================
- Coverage    59.18%   59.18%   -0.01%     
===========================================
  Files         2819     2819              
  Lines        67717    67716       -1     
  Branches     15080    15080              
===========================================
- Hits         40077    40076       -1     
  Misses       24818    24818              
  Partials      2822     2822              
Flag Coverage Δ
unit 75.00% <ø> (ø)

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

@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch from 7c92475 to df876a0 Compare December 13, 2024 17:58
@abhinavkrin abhinavkrin changed the title [WIP] feat: add endpoints groups.membersOrderedByRole channels.membersOrderedByRole feat: add endpoints groups.membersOrderedByRole channels.membersOrderedByRole Dec 16, 2024
@abhinavkrin abhinavkrin marked this pull request as ready for review December 16, 2024 15:48
@abhinavkrin abhinavkrin requested review from a team as code owners December 16, 2024 15:48
Copy link
Member

@MarcosSpessatto MarcosSpessatto left a comment

Choose a reason for hiding this comment

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

I think we could create a rooms.membersOrderedByRole instead of creating one for each room type.

Also, we need to create some mock data to test the aggregation part and its performance.
@ricardogarim can you help us with that.

.changeset/silly-kings-approve.md Outdated Show resolved Hide resolved
apps/meteor/tests/end-to-end/api/channels.ts Outdated Show resolved Hide resolved
apps/meteor/tests/end-to-end/api/channels.ts Outdated Show resolved Hide resolved
@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch 2 times, most recently from ae9d2e1 to c5fa198 Compare December 17, 2024 16:54
Copy link
Member

@MarcosSpessatto MarcosSpessatto left a comment

Choose a reason for hiding this comment

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

It looks good to me, we just need to do some perf tests with some fake data to ensure the query perf

@scuciatto scuciatto modified the milestones: 7.2.0, 7.3.0 Dec 20, 2024
@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch from 6ceb8e3 to e8d16bf Compare December 20, 2024 14:56
@MartinSchoeler
Copy link
Contributor

Hey, it seems that the total property is missing from the endpoint result

(Old Members Endpoint)
Screenshot 2024-12-27 at 16 21 12

(New Members Endpoint)
Screenshot 2024-12-27 at 16 21 30

@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch from e8d16bf to ff2748b Compare January 10, 2025 14:37
apps/meteor/server/lib/findUsersOfRoomOrderedByRole.ts Outdated Show resolved Hide resolved
apps/meteor/server/startup/migrations/v320.ts Outdated Show resolved Hide resolved
apps/meteor/server/startup/migrations/v320.ts Outdated Show resolved Hide resolved
apps/meteor/server/startup/migrations/v320.ts Outdated Show resolved Hide resolved
packages/models/src/models/Subscriptions.ts Outdated Show resolved Hide resolved
@abhinavkrin abhinavkrin changed the title feat: add endpoints groups.membersOrderedByRole channels.membersOrderedByRole feat: add endpoint rooms.membersOrderedByRole Jan 13, 2025
apps/meteor/app/api/server/v1/rooms.ts Show resolved Hide resolved
apps/meteor/server/lib/findUsersOfRoomOrderedByRole.ts Outdated Show resolved Hide resolved
packages/rest-typings/src/v1/rooms.ts Outdated Show resolved Hide resolved
apps/meteor/server/startup/migrations/v320.ts Outdated Show resolved Hide resolved
@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch from 1736241 to 89ea1e5 Compare January 15, 2025 14:20
Signed-off-by: Abhinav Kumar <[email protected]>
Signed-off-by: Abhinav Kumar <[email protected]>
Signed-off-by: Abhinav Kumar <[email protected]>
Signed-off-by: Abhinav Kumar <[email protected]>
Signed-off-by: Abhinav Kumar <[email protected]>
KevLehman
KevLehman previously approved these changes Jan 17, 2025
@abhinavkrin abhinavkrin modified the milestones: 7.4.0, 7.3.0 Jan 17, 2025
ricardogarim
ricardogarim previously approved these changes Jan 17, 2025
Signed-off-by: Abhinav Kumar <[email protected]>
Co-authored-by: Abhinav Kumar <[email protected]>
@MartinSchoeler MartinSchoeler dismissed stale reviews from ricardogarim and KevLehman via 7ee0f4b January 17, 2025 18:40
@MartinSchoeler MartinSchoeler requested a review from a team as a code owner January 17, 2025 18:40
@MartinSchoeler MartinSchoeler added the stat: QA assured Means it has been tested and approved by a company insider label Jan 17, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Jan 17, 2025
@kodiakhq kodiakhq bot merged commit c8e8518 into develop Jan 17, 2025
49 checks passed
@kodiakhq kodiakhq bot deleted the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch January 17, 2025 21:27
This was referenced Jan 20, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants