Skip to content

refactor: Rooms out of DB Watcher#32305

Merged
kodiakhq[bot] merged 22 commits intodevelopfrom
refactor/rooms-out-of-db-watcher
May 9, 2024
Merged

refactor: Rooms out of DB Watcher#32305
kodiakhq[bot] merged 22 commits intodevelopfrom
refactor/rooms-out-of-db-watcher

Conversation

@ricardogarim
Copy link
Copy Markdown
Member

@ricardogarim ricardogarim commented Apr 24, 2024

As per the updates mentioned in PROJ-7 SCA-4 and ADR #74, this pull request focuses on relocating Rooms entity out of DB Watcher service.

Quick context to public readers

In essence, this modification empowers RocketChat's app to directly call listeners through the api.broadcast global function, eliminating the reliance on MongoDB Change Stream data propagation

Why is this beneficial? It provides better control over notifying users by enabling more precise use-case management. Unlike Change Streams, which notify every action on Mongo's documents and sometimes might result in unnecessary duplicate notifications. Moreover, it contributes to the future removal of the DB Watcher deployment, thereby optimizing resource utilization.

Proposed changes

Key changes include:

  • Conditionally incorporating Room entity import within DB watchers on application startup based on the dbWatchersDisabled flag.
  • Enabling support for the following use cases to directly trigger watch.rooms listener event, subject to the dbWatchersDisabled flag.
Updated use cases.
Use Case Route/Trigger Notes
addUserToRoom POST api/v1/method.call/addUsersToRoom Reduced from 2 to 1 WS event sent to client.
archiveRoom POST api/v1/rooms.saveRoomSettings
POST api/v1/rooms.changeArchivationState
Reduced from 2 to 1 WS event sent to client.
cleanRoomHistory POST api/v1/rooms.cleanHistory
createDirectRoom POST api/v1/dm.create
createRoom POST api/v1/groups.create Reduced from 2 to 1 WS event sent to client.
deleteRoom POST api/v1/rooms.delete
deleteUser POST api/v1/users.delete Reduced from 3 to 1 WS event sent to client.
removeUserFromRoom from methods POST api/v1/groups.kick Reduced from 2 to 1 WS event sent to client.
saveRoomSettings POST api/v1/rooms.saveRoomSettings General UC to all updates on description, topics, names and states of a given room.
sendMessage POST api/v1/method.call/sendMessage Reduced from 2 to 1 WS event sent to client.
setRoomAvatar POST api/v1/rooms.saveRoomSettings
unarchiveRoom POST api/v1/rooms.saveRoomSettings
POST api/v1/rooms.changeArchivationState
muteUserInRoom POST api/v1/method.call/muteUserInRoom Reduced from 3 to 1 WS event sent to client.
unmuteUserInRoom POST api/v1/method.call/unmuteUserInRoom Reduced from 3 to 1 WS event sent to client.
updateUsernameReferences POST api/v1/users.update
deleteMessage POST api/v1/method.call/deleteMessage Reduced from 2 to 1 WS event sent to client.
setRoomKeyID POST api/v1/e2e.setRoomKeyID
pinMessage POST api/v1/chat.pinMessage Reduced from 3 to 1 WS event sent to client.
unPinMessage POST api/v1/chat.unPinMessage Reduced from 2 to 1 WS event sent to client.
starMessage POST api/v1/chat.starMessage Reduced from 2 to 1 WS event sent to client.
unStarMessage POST api/v1/chat.unStarMessage Reduced from 2 to 1 WS event sent to client.
setReaction POST api/v1/method.call/setReaction Reduced from 2 to 1 WS event sent to client.
unsetReaction POST api/v1/chat.react Reduced from 2 to 1 WS event sent to client.
federation event handlers

Steps to test or reproduce

  1. Start RocketChat's application with the DISABLE_DB_WATCHERS flag set to true.
  2. Perform a POST request to above given endpoints available on updated use cases.
  3. Observe the websocket events received. Each event should be of eventName rooms-changed, containing all changed fields as well as the updated room identification data.

Further comments

To maintain consistency and avoid potential regressions, event names and signatures have been kept unchanged on both the client and app sides. This decision streamlines efforts and mitigates the risk of unintended consequences. Additionally, considering time constraints and the absence of tests for this core server component, this direction was chosen as the most pragmatic approach.

Rooms model WBS. Used to guide changes discovery.
🔄 Work in progress
✅ Done
➖ Not applicable

Function Status
findOneByRoomIdAndUserId
findManyByRoomIds
findPaginatedByIds
getMostRecentAverageChatDurationTime
findByNameOrFnameContainingAndTypes
findByTeamId
findPaginatedByTeamIdContainingNameAndDefault
findByTeamIdAndRoomsId
findRoomsByNameOrFnameStarting
findRoomsWithoutDiscussionsByRoomIds
findPaginatedRoomsWithoutDiscussionsByRoomIds
findChannelAndGroupListWithoutTeamsByNameStartingByOwner
unsetTeamId 🔄
unsetTeamById 🔄
setTeamById 🔄
setTeamMainById 🔄
setTeamByIds 🔄
setTeamDefaultById 🔄
findChannelsWithNumberOfMessagesBetweenDate
countChannelsWithNumberOfMessagesBetweenDate
findOneByName
findDefaultRoomsForTeam
incUsersCountByIds
findOneByNameOrFname
findOneByJoinCodeAndId
findOneByNonValidatedName
allRoomSourcesCount
findByBroadcast
findByActiveLivestream
setAsFederated 🔄
setRoomTypeById 🔄
setRoomNameById 🔄
setFnameById 🔄
setRoomTopicById
findByE2E
findE2ERoomById
findRoomsInsideTeams
findOneDirectRoomContainingAllUserIDs
countByType
findPaginatedByNameOrFNameAndRoomIdsIncludingTeamRooms
findPaginatedContainingNameOrFNameInIdsAsTeamMain
findPaginatedByTypeAndIds
findFederatedRooms
findFederatedRooms
findCountOfRoomsWithActiveCalls
findBiggestFederatedRoomInNumberOfUsers
findSmallestFederatedRoomInNumberOfUsers
countFederatedRooms
incMsgCountById
decreaseMessageCountById
findOneByIdOrName
setCallStatus
setCallStatusAndCallStartTime
setReactionsInLastMessage
unsetReactionsInLastMessage
unsetAllImportIds
updateLastMessageStar
setLastMessagePinned
setLastMessageAsRead
setDescriptionById
setStreamingOptionsById
setReadOnlyById
setDmReadOnlyByUserId
getDirectConversationsByUserId
setAllowReactingWhenReadOnlyById
setAvatarData
unsetAvatarData
setSystemMessagesById
setE2eKeyId
findOneByImportId
findOneByNameAndNotId
findOneByDisplayName
findOneByNameAndType
findById
findByIds
findByType
findByTypeInIds
findBySubscriptionUserId
findBySubscriptionUserIdUpdatedAfter
findByNameAndTypeNotDefault
findByNameOrFNameAndTypesNotInIds
findByDefaultAndTypes
findDirectRoomContainingAllUsernames
findByTypeAndName
findByTypeAndNameOrId
findByTypeAndNameContaining
findByTypeInIdsAndNameContaining
findGroupDMsByUids
find1On1ByUserId
findByCreatedOTR
addImportIds 🔄
archiveById
unarchiveById
setNameById 🔄
incMsgCountAndSetLastMessageById
incUsersCountById 🔄
incUsersCountNotDMsByIds
setLastMessageById
resetLastMessageById
replaceUsername
replaceMutedUsername
replaceUsernameOfUserByUserId
setJoinCodeById
setTypeById 🔄
setTopicById 🔄
setAnnouncementById
setCustomFieldsById
muteUsernameByRoomId
muteReadOnlyUsernameByRoomId
unmuteMutedUsernameByRoomId
unmuteReadOnlyUsernameByRoomId
saveFeaturedById
saveDefaultById
saveFavoriteById
saveRetentionEnabledById
saveRetentionMaxAgeById
saveRetentionExcludePinnedById
saveRetentionIgnoreThreadsById
saveRetentionFilesOnlyById
saveRetentionOverrideGlobalById
saveEncryptedById
updateGroupDMsRemovingUsernamesByUsername
createWithIdTypeAndName
createWithFullRoomData
removeById
removeByIds
removeDirectRoomContainingUsername
countDiscussions
setOTRForDMByRoomID 🔄

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 24, 2024

⚠️ No Changeset found

Latest commit: 7620231

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 24, 2024

Codecov Report

Attention: Patch coverage is 9.09091% with 30 lines in your changes are missing coverage. Please review.

Project coverage is 54.93%. Comparing base (724ba3a) to head (7620231).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #32305      +/-   ##
===========================================
- Coverage    55.57%   54.93%   -0.64%     
===========================================
  Files         2404     2353      -51     
  Lines        52896    51951     -945     
  Branches     10862    10627     -235     
===========================================
- Hits         29395    28540     -855     
+ Misses       20895    20844      -51     
+ Partials      2606     2567      -39     
Flag Coverage Δ
e2e 53.70% <ø> (-1.17%) ⬇️
unit 73.30% <9.09%> (-0.21%) ⬇️

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

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Apr 24, 2024

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

@ricardogarim ricardogarim changed the title refactor: rooms out of DB Watcher refactor: Rooms out of DB Watcher Apr 29, 2024
@ricardogarim ricardogarim marked this pull request as ready for review April 29, 2024 12:05
@ricardogarim ricardogarim requested review from a team as code owners April 29, 2024 12:05
@ricardogarim ricardogarim requested a review from a team as a code owner May 8, 2024 16:26
sampaiodiego
sampaiodiego previously approved these changes May 8, 2024
sampaiodiego
sampaiodiego previously approved these changes May 8, 2024
@sampaiodiego sampaiodiego added the stat: QA assured Means it has been tested and approved by a company insider label May 8, 2024
@sampaiodiego sampaiodiego added this to the 6.9 milestone May 8, 2024
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label May 8, 2024
sampaiodiego
sampaiodiego previously approved these changes May 8, 2024
Copy link
Copy Markdown
Member

@KevLehman KevLehman left a comment

Choose a reason for hiding this comment

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

don't forget LivechatRooms :please:

@kodiakhq kodiakhq bot merged commit 3b3275f into develop May 9, 2024
@kodiakhq kodiakhq bot deleted the refactor/rooms-out-of-db-watcher branch May 9, 2024 19:40
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.

3 participants