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.
This commit is contained in:
Calvin Montgomery 2018-06-06 22:45:08 -07:00
parent 3413c3bdaa
commit fa49921866
2 changed files with 9 additions and 7 deletions

View file

@ -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();
},

View file

@ -3364,11 +3364,13 @@ CyTube.ui.changeVideoWidth = function uiChangeVideoWidth(direction) {
handleVideoResize();
};
CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList = function (data) {
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 = $("<div/>")
.addClass("userlist_item");
var icon = $("<span/>").appendTo(div);