Update realtime to use timer to avoid memory leaks on busy tick

This commit is contained in:
Wu Cheng-Han 2017-02-03 21:47:38 +08:00
parent 92ad67b813
commit ef0ac7768d
1 changed files with 11 additions and 5 deletions

View File

@ -354,9 +354,12 @@ function clearSocketQueue(queue, socket) {
}
function connectNextSocket() {
isConnectionBusy = false;
if (connectionSocketQueue.length > 0)
startConnection(connectionSocketQueue[0]);
setTimeout(function () {
isConnectionBusy = false;
if (connectionSocketQueue.length > 0) {
startConnection(connectionSocketQueue[0]);
}
}, 1);
}
function interruptConnection(socket, note, user) {
@ -693,8 +696,11 @@ function operationCallback(socket, operation) {
}
note.tempUsers[userId] = Date.now();
}
// save authorship
note.authorship = models.Note.updateAuthorshipByOperation(operation, userId, note.authorship);
// save authorship - use timer here because it's an O(n) complexity algorithm
setImmediate(function () {
note.authorship = models.Note.updateAuthorshipByOperation(operation, userId, note.authorship);
});
}
function updateHistory(userId, note, time) {
var noteId = note.alias ? note.alias : LZString.compressToBase64(note.id);