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

View file

@ -354,10 +354,13 @@ function clearSocketQueue(queue, socket) {
}
function connectNextSocket() {
setTimeout(function () {
isConnectionBusy = false;
if (connectionSocketQueue.length > 0)
if (connectionSocketQueue.length > 0) {
startConnection(connectionSocketQueue[0]);
}
}, 1);
}
function interruptConnection(socket, note, user) {
if (note) delete note;
@ -693,8 +696,11 @@ function operationCallback(socket, operation) {
}
note.tempUsers[userId] = Date.now();
}
// save 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);