refactor: Subscriptions out of DB Watcher
As per the updates mentioned in PROJ-7, SCA-13 and ADR #74, this pull request focuses on relocating Subscriptions model out of DB Watcher service.
Context
This modification enhances RocketChat's app by allowing it to directly call listeners through the api.broadcast global function, bypassing the need for MongoDB Change Stream data propagation.
This change offers better control over user notifications via Web Sockets, enabling more precise management of use-cases. Instead of notifying every database change, we can now send an api.broadcast call only when necessary, reducing overall network messages. Additionally, this contributes to the future removal of the DB Watcher deployment, optimizing resource utilization.
Proposed changes
Key changes include:
- Conditionally incorporating Subscriptions entity import within DB watchers on application startup based on the
dbWatchersDisabledflag. - Enabling support for the following use cases to directly trigger
watch.subscriptionslistener event, subject to thedbWatchersDisabledflag.
Updated Use Cases
| Use Case | Route/Trigger | Notes |
|---|---|---|
| removeRolesByUserId | applyRoomRolesToUser; Roles raw models removeUserRoles | |
| addRolesByUserId | applyRoomRolesToUser; Roles raw models addUserRoles | |
| setAsReadByRoomIdAndUserId | post route 'subscriptions.read'; afterSaveMessage callback | |
| updateAllRoomTypesByRoomId | updateRoomType | |
| removeByRoomId | deleteRoom server functions (add api route too); LivechatClass.closeRoom; RocketChatRoomAdapter.removeDirectMessageRoom | |
| incUnreadForRoomIdExcludingUserIds | updateUsersSubscriptions | |
| setAlertForRoomIdExcludingUserId | updateUsersSubscriptions | |
| setOpenForRoomIdExcludingUserId | updateUsersSubscriptions | |
| updateNameAndFnameByRoomId | RocketChatRoomAdapter updateRoomName and updateDisplayRoomName | |
| setGroupE2EKey | method meteor 'e2e.updateGroupKey'; handleSuggestedGroupKey | |
| setGroupE2ESuggestedKey | method meteor 'e2e.updateGroupKey' | |
| unsetGroupE2ESuggestedKey | handleSuggestedGroupKey | |
| setOnHoldByRoomId | OmnichannelEE > placeRoomOnHold | |
| unsetOnHoldByRoomId | onCloseLivechat; omnichannelEE.resumeRoomOnHold | |
| updateUnreadAlertById | meteor method saveNotificationSettings | |
| updateNotificationsPrefById | meteor method saveNotificationSettings | |
| updateHideMentionStatusById | meteor method saveNotificationSettings | |
| updateDisableNotificationsById | meteor method saveNotificationSettings | |
| clearAudioNotificationValueById | meteor method saveNotificationSettings saveAudioNotificationValue | |
| updateAudioNotificationValueById | meteor method saveNotificationSettings saveAudioNotificationValue | |
| updateMuteGroupMentions | meteor method saveNotificationSettings | |
| updateHideUnreadStatusById | meteor method saveNotificationSettings | |
| updateAutoTranslateLanguageById | meteor method 'autoTranslate.saveSettings' | |
| updateAutoTranslateById | meteor method 'autoTranslate.saveSettings' | |
| removeByVisitorToken | LivechatClass cleanGuestHistory | |
| changeDepartmentByRoomId | livechat helper updateChatDepartment | |
| updateAllAutoTranslateLanguagesByUserId | saveUserPreferences | |
| disableAutoTranslateByRoomId | saveRoomEncrypted | |
| resetUserE2EKey | resetUserE2EEncriptionKey | |
| setAsUnreadByRoomIdAndUserId | meteor method unreadMessages | |
| archiveByRoomId | ImportDataConverter.archiveRoomById; archiveRoom function | |
| unarchiveByRoomId | unarchiveRoom function | |
| updateNameAndAlertByRoomId | updateRoomName | |
| setCustomFieldsDirectMessagesByUserId | ||
| setFavoriteByRoomIdAndUserId | meteor method toggleFavorite | |
| hideByRoomIdAndUserId | hideRoomMethod | |
| updateNameAndFnameById | updateGroupDMsName | |
| setUserUsernameByUserId | updateUsernameReferences | |
| updateFnameByRoomId | updateFName | |
| updateDisplayNameByRoomId | registerContact; LivechatClass.saveRoomInfo | |
| updateDirectNameAndFnameByName | updateUsernameReferences | |
| incGroupMentionsAndUnreadForRoomIdExcludingUserId | incGroupMentions | |
| unsetBlockedByRoomId | unblockUser | |
| setLastReplyForRoomIdAndUserIds | updateThreadUsersSubscriptions | |
| updateCustomFieldsByRoomId | saveRoomCustomFields | |
| setOpenForRoomIdAndUserIds | reply; updateThreadUsersSubscriptions | |
| setAlertForRoomIdAndUserIds | reply; updateThreadUsersSubscriptions | |
| updateTypeByRoomId | saveRoomType | |
| setBlockedByRoomId | meteor method blockUser | |
| incUserMentionsAndUnreadForRoomIdAndUserIds | updateUsersSubscriptions | |
| ignoreUser | meteor method ignoreUser | |
| addRoleById | meteor methods addRoomLeader, addRoomModerator, and addRoomOwner | |
| removeRoleById | removeRoomLeader, removeRoomModerator, and removeRoomOwner | |
| setArchivedByUsername | deactivate > setArchivedByUsername; CROWD.syncDataToUser > setArchivedByUsername; meteor method setUserActiveStatus; ldapeemanager > disableMissingUsers and updateExistingUsers; ImportDataConverter > updateUser | |
| updateUserHighlights | saveUserPreferences | |
| updateNotificationUserPreferences | saveUserPreferences | |
| clearNotificationUserPreferences | saveUserPreferences | |
| removeByUserId | deleteUser | |
| createWithRoomAndUser | ||
| createWithRoomAndManyUsers | ||
| removeByRoomIdAndUserId | ||
| removeByRoomIds | ||
| addUnreadThreadByRoomIdAndUserIds | ||
| removeUnreadThreadByRoomIdAndUserId | ||
| openByRoomIdAndUserId | meteor method openRoom | |
| removeUnreadThreadsByRoomId |
Steps to test or reproduce
- Start RocketChat's application with the
DISABLE_DB_WATCHERSenvironment variable set totrue. - Perform HTTP requests or simulate use cases listed in the above table.
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.
Looks like this PR is ready to merge! 🎉 If you have any trouble, please check the PR guidelines
⚠️ No Changeset found
Latest commit: 3af69436610d60cb2b0d22a312bb2ff54a8c203e
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 Report
Attention: Patch coverage is 23.07692% with 60 lines in your changes missing coverage. Please review.
Project coverage is 59.40%. Comparing base (
dd37ea1) to head (3af6943). Report is 3 commits behind head on develop.
Additional details and impacted files
@@ Coverage Diff @@
## develop #32540 +/- ##
===========================================
- Coverage 59.43% 59.40% -0.04%
===========================================
Files 2547 2547
Lines 63265 63310 +45
Branches 14237 14248 +11
===========================================
+ Hits 37604 37611 +7
- Misses 22941 22980 +39
+ Partials 2720 2719 -1
| Flag | Coverage Δ | |
|---|---|---|
| unit | 75.84% <23.07%> (-0.20%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.