PadMessageHandler: Parallelize client updates

Multiple clients are updated in parallel, but multiple revisions sent
to a particular client are still sent sequentially.
This commit is contained in:
Richard Hansen 2021-04-13 00:00:21 -04:00
parent 770755debf
commit 14d4aadfe4

View file

@ -715,10 +715,10 @@ exports.updatePadClients = async (pad) => {
// but benefit of reusing cached revision object is HUGE // but benefit of reusing cached revision object is HUGE
const revCache = {}; const revCache = {};
socket: for (const socket of roomSockets) { await Promise.all(roomSockets.map(async (socket) => {
const sessioninfo = sessioninfos[socket.id]; const sessioninfo = sessioninfos[socket.id];
// The user might have disconnected since _getRoomSockets() was called. // The user might have disconnected since _getRoomSockets() was called.
if (sessioninfo == null) continue; if (sessioninfo == null) return;
while (sessioninfo.rev < pad.getHeadRevisionNumber()) { while (sessioninfo.rev < pad.getHeadRevisionNumber()) {
const r = sessioninfo.rev + 1; const r = sessioninfo.rev + 1;
@ -754,12 +754,12 @@ exports.updatePadClients = async (pad) => {
socket.json.send(msg); socket.json.send(msg);
} catch (err) { } catch (err) {
messageLogger.error(`Failed to notify user of new revision: ${err.stack || err}`); messageLogger.error(`Failed to notify user of new revision: ${err.stack || err}`);
continue socket; return;
} }
sessioninfo.time = currentTime; sessioninfo.time = currentTime;
sessioninfo.rev = r; sessioninfo.rev = r;
} }
} }));
}; };
/** /**