summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu Cheng-Han2016-10-10 20:25:48 +0800
committerWu Cheng-Han2016-10-10 20:25:48 +0800
commit1cae0c5b7f63bd9049fbfbc891f77d1b2af3ec99 (patch)
treec15068f1439617b1fa583cc8e1e02a308e415fa9
parentd23ced1fba0e4bc7ecbc00d0a2376f34bab80509 (diff)
Update to prevent duplicate socket push in queue in order to lower down server loading
Diffstat (limited to '')
-rw-r--r--lib/realtime.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/realtime.js b/lib/realtime.js
index 9c3d5b2e..ae624c24 100644
--- a/lib/realtime.js
+++ b/lib/realtime.js
@@ -327,6 +327,15 @@ function emitRefresh(socket) {
socket.emit('refresh', out);
}
+function isDuplicatedInSocketQueue(queue, socket) {
+ for (var i = 0; i < queue.length; i++) {
+ if (queue[i] && queue[i].id == socket.id) {
+ return true;
+ }
+ }
+ return false;
+}
+
function clearSocketQueue(queue, socket) {
for (var i = 0; i < queue.length; i++) {
if (!queue[i] || queue[i].id == socket.id) {
@@ -654,6 +663,8 @@ function connection(socket) {
if (!noteId) {
return failConnection(404, 'note id not found', socket);
}
+
+ if (isDuplicatedInSocketQueue(socket, connectionSocketQueue)) return;
// store noteId in this socket session
socket.noteId = noteId;
@@ -830,6 +841,7 @@ function connection(socket) {
//when a new client disconnect
socket.on('disconnect', function () {
+ if (isDuplicatedInSocketQueue(socket, disconnectSocketQueue)) return;
disconnectSocketQueue.push(socket);
disconnect(socket);
});