From fa499218660ab90fb4ccf242d093721483f806d5 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Wed, 6 Jun 2018 22:45:08 -0700 Subject: [PATCH] Speed up join by avoiding quadratic userlist code At some point the entire user presence logic needs to be refactored for efficiency, but this at least gives a huge reduction in first page load time for large channels. --- www/js/callbacks.js | 4 ++-- www/js/util.js | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/www/js/callbacks.js b/www/js/callbacks.js index 0f5658de..1d7b3b10 100644 --- a/www/js/callbacks.js +++ b/www/js/callbacks.js @@ -487,13 +487,13 @@ Callbacks = { userlist: function(data) { $(".userlist_item").remove(); for(var i = 0; i < data.length; i++) { - CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList(data[i]); + CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList(data[i], false); } sortUserlist(); }, addUser: function(data) { - CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList(data); + CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList(data, true); sortUserlist(); }, diff --git a/www/js/util.js b/www/js/util.js index dc564307..ccb29493 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -3364,11 +3364,13 @@ CyTube.ui.changeVideoWidth = function uiChangeVideoWidth(direction) { handleVideoResize(); }; -CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList = function (data) { - var user = findUserlistItem(data.name); - // Remove previous instance of user, if there was one - if(user !== null) - user.remove(); +CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList = function (data, removePrev) { + if (removePrev) { + var user = findUserlistItem(data.name); + // Remove previous instance of user, if there was one + if(user !== null) + user.remove(); + } var div = $("
") .addClass("userlist_item"); var icon = $("").appendTo(div);