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: function(data) {
$(".userlist_item").remove(); $(".userlist_item").remove();
for(var i = 0; i < data.length; i++) { 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(); sortUserlist();
}, },
addUser: function(data) { 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(); sortUserlist();
}, },

View file

@ -3364,11 +3364,13 @@ CyTube.ui.changeVideoWidth = function uiChangeVideoWidth(direction) {
handleVideoResize(); 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) {
var user = findUserlistItem(data.name); if (removePrev) {
// Remove previous instance of user, if there was one var user = findUserlistItem(data.name);
if(user !== null) // Remove previous instance of user, if there was one
user.remove(); if(user !== null)
user.remove();
}
var div = $("<div/>") var div = $("<div/>")
.addClass("userlist_item"); .addClass("userlist_item");
var icon = $("<span/>").appendTo(div); var icon = $("<span/>").appendTo(div);