summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu Cheng-Han2017-02-03 21:47:38 +0800
committerWu Cheng-Han2017-02-03 21:47:38 +0800
commitef0ac7768d5dbd6a99c4126a1ed8b091f004d3bf (patch)
tree7cc7e891382aee3ccddaf393d6d3adf73df9604c
parent92ad67b813c3b940f619983c7daee7cdf21c3f4e (diff)
Update realtime to use timer to avoid memory leaks on busy tick
-rw-r--r--lib/realtime.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/realtime.js b/lib/realtime.js
index def8f217..c1db6886 100644
--- a/lib/realtime.js
+++ b/lib/realtime.js
@@ -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);