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