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

Remove isChunked from pusher subscriptions #9203

Merged
merged 6 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/libs/Pusher/pusher.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ function getChannel(channelName) {
* @param {Pusher.Channel} channel
* @param {String} eventName
* @param {Function} [eventCallback]
* @param {Boolean} [isChunked] Do we expect this channel to send chunked/separate blocks of data that need recombining?
*
* @private
*/
function bindEventToChannel(channel, eventName, eventCallback = () => {}, isChunked = false) {
function bindEventToChannel(channel, eventName, eventCallback = () => {}) {
if (!eventName) {
return;
}
Expand All @@ -120,7 +119,7 @@ function bindEventToChannel(channel, eventName, eventCallback = () => {}, isChun
Log.alert('[Pusher] Unable to parse JSON response from Pusher', {error: err, eventData});
return;
}
if (!isChunked) {
if (data.id === undefined || data.chunk === undefined || data.final === undefined) {
eventCallback(data);
return;
}
Expand Down Expand Up @@ -169,9 +168,6 @@ function bindEventToChannel(channel, eventName, eventCallback = () => {}, isChun
* @param {String} channelName
* @param {String} eventName
* @param {Function} [eventCallback]
* @param {Boolean} [isChunked] This parameters tells us whether or not we expect the result to come in individual
* pieces/chunks (because it exceeds
* the 10kB limit that pusher has).
* @param {Function} [onResubscribe] Callback to be called when reconnection happen
*
* @return {Promise}
Expand All @@ -182,7 +178,6 @@ function subscribe(
channelName,
eventName,
eventCallback = () => {},
isChunked = false,
onResubscribe = () => {},
) {
return new Promise((resolve, reject) => {
Expand All @@ -201,7 +196,7 @@ function subscribe(
channel.bind('pusher:subscription_succeeded', () => {
// Check so that we do not bind another event with each reconnect attempt
if (!isBound) {
bindEventToChannel(channel, eventName, eventCallback, isChunked);
bindEventToChannel(channel, eventName, eventCallback);
resolve();
isBound = true;
return;
Expand All @@ -225,7 +220,7 @@ function subscribe(
reject(error);
});
} else {
bindEventToChannel(channel, eventName, eventCallback, isChunked);
bindEventToChannel(channel, eventName, eventCallback);
resolve();
}
});
Expand Down
13 changes: 4 additions & 9 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,8 @@ function getReportChannelName(reportID) {
*
* @param {String} eventName
* @param {Function} onEvent
* @param {Boolean} isChunked
*/
function subscribeToPrivateUserChannelEvent(eventName, onEvent, isChunked = false) {
function subscribeToPrivateUserChannelEvent(eventName, onEvent) {
const pusherChannelName = `private-encrypted-user-accountID-${currentUserAccountID}${CONFIG.PUSHER.SUFFIX}`;

/**
Expand Down Expand Up @@ -759,7 +758,7 @@ function subscribeToPrivateUserChannelEvent(eventName, onEvent, isChunked = fals
Log.hmmm('[Report] Failed to subscribe to Pusher channel', false, {error, pusherChannelName, eventName});
}

Pusher.subscribe(pusherChannelName, eventName, onEventPush, isChunked, onPusherResubscribeToPrivateUserChannel)
Pusher.subscribe(pusherChannelName, eventName, onEventPush, onPusherResubscribeToPrivateUserChannel)
.catch(onSubscriptionFailed);
}

Expand All @@ -781,17 +780,13 @@ function subscribeToUserEvents() {
subscribeToPrivateUserChannelEvent(Pusher.TYPE.REPORT_COMMENT, pushJSON => updateReportWithNewAction(pushJSON.reportID, pushJSON.reportAction, pushJSON.notificationPreference));

// Live-update a report's actions when a 'chunked report comment' event is received.
subscribeToPrivateUserChannelEvent(
Pusher.TYPE.REPORT_COMMENT_CHUNK,
pushJSON => updateReportWithNewAction(pushJSON.reportID, pushJSON.reportAction, pushJSON.notificationPreference),
true,
);
subscribeToPrivateUserChannelEvent(Pusher.TYPE.REPORT_COMMENT_CHUNK, pushJSON => updateReportWithNewAction(pushJSON.reportID, pushJSON.reportAction, pushJSON.notificationPreference));

// Live-update a report's actions when an 'edit comment' event is received.
subscribeToPrivateUserChannelEvent(Pusher.TYPE.REPORT_COMMENT_EDIT, pushJSON => updateReportActionMessage(pushJSON.reportID, pushJSON.sequenceNumber, pushJSON.message));

// Live-update a report's actions when an 'edit comment chunk' event is received.
subscribeToPrivateUserChannelEvent(Pusher.TYPE.REPORT_COMMENT_EDIT_CHUNK, pushJSON => updateReportActionMessage(pushJSON.reportID, pushJSON.sequenceNumber, pushJSON.message), true);
subscribeToPrivateUserChannelEvent(Pusher.TYPE.REPORT_COMMENT_EDIT_CHUNK, pushJSON => updateReportActionMessage(pushJSON.reportID, pushJSON.sequenceNumber, pushJSON.message));
Copy link
Contributor

Choose a reason for hiding this comment

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

after we have a 80%+ with this version, we can clean this up and change PHP to not prepend 'chunked-' in the chunked messages. That way we'll only subscribe to one channel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup! Once this is widely rolled out (do we track that anywhere?), we can move on with removing the channel from PHP and here

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we might have some info on firebase about the rollout


// Live-update a report's pinned state when a 'report toggle pinned' event is received.
subscribeToPrivateUserChannelEvent(Pusher.TYPE.REPORT_TOGGLE_PINNED, pushJSON => updateReportPinnedState(pushJSON.reportID, pushJSON.isPinned));
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function subscribeToUserEvents() {
// Live-update an user's preferred locale
Pusher.subscribe(pusherChannelName, Pusher.TYPE.PREFERRED_LOCALE, (pushJSON) => {
Onyx.merge(ONYXKEYS.NVP_PREFERRED_LOCALE, pushJSON.preferredLocale);
}, false,
},
() => {
NetworkConnection.triggerReconnectionCallbacks('pusher re-subscribed to private user channel');
})
Expand All @@ -320,7 +320,7 @@ function subscribeToUserEvents() {
// Subscribe to screen share requests sent by GuidesPlus agents
Pusher.subscribe(pusherChannelName, Pusher.TYPE.SCREEN_SHARE_REQUEST, (pushJSON) => {
Onyx.merge(ONYXKEYS.SCREEN_SHARE_REQUEST, pushJSON);
}, false,
},
() => {
NetworkConnection.triggerReconnectionCallbacks('pusher re-subscribed to private user channel');
})
Expand Down Expand Up @@ -351,7 +351,7 @@ function subscribeToExpensifyCardUpdates() {
} else {
Onyx.merge(ONYXKEYS.USER, {isCheckingDomain: pushJSON.isCheckingDomain});
}
}, false,
},
() => {
NetworkConnection.triggerReconnectionCallbacks('pusher re-subscribed to private user channel');
})
Expand Down