mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 14:04:27 -05:00
Update to prevent duplicate socket push in queue in order to lower down server loading
This commit is contained in:
parent
d23ced1fba
commit
1cae0c5b7f
1 changed files with 12 additions and 0 deletions
|
@ -327,6 +327,15 @@ function emitRefresh(socket) {
|
||||||
socket.emit('refresh', out);
|
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) {
|
function clearSocketQueue(queue, socket) {
|
||||||
for (var i = 0; i < queue.length; i++) {
|
for (var i = 0; i < queue.length; i++) {
|
||||||
if (!queue[i] || queue[i].id == socket.id) {
|
if (!queue[i] || queue[i].id == socket.id) {
|
||||||
|
@ -655,6 +664,8 @@ function connection(socket) {
|
||||||
return failConnection(404, 'note id not found', socket);
|
return failConnection(404, 'note id not found', socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDuplicatedInSocketQueue(socket, connectionSocketQueue)) return;
|
||||||
|
|
||||||
// store noteId in this socket session
|
// store noteId in this socket session
|
||||||
socket.noteId = noteId;
|
socket.noteId = noteId;
|
||||||
|
|
||||||
|
@ -830,6 +841,7 @@ function connection(socket) {
|
||||||
|
|
||||||
//when a new client disconnect
|
//when a new client disconnect
|
||||||
socket.on('disconnect', function () {
|
socket.on('disconnect', function () {
|
||||||
|
if (isDuplicatedInSocketQueue(socket, disconnectSocketQueue)) return;
|
||||||
disconnectSocketQueue.push(socket);
|
disconnectSocketQueue.push(socket);
|
||||||
disconnect(socket);
|
disconnect(socket);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue