From ac548777fc93e28e27ef3659df8729a1cf3fd0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Fri, 7 Mar 2014 17:56:48 +0000 Subject: [PATCH] Defer nicklist loading until buffer is opened Drastically improves startup time for users with buffers that have thousands of users --- js/glowingbear.js | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 7b21ed5..97aabfc 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -275,13 +275,6 @@ function($rootScope, ); }; - var _requestNicklist = function() { - return ngWebsockets.send( - weeChat.Protocol.formatNicklist({ - }) - ); - }; - var _requestBufferInfos = function() { return ngWebsockets.send( weeChat.Protocol.formatHdata({ @@ -322,10 +315,6 @@ function($rootScope, handlers.handleHotlistInfo(hotlist); }); - _requestNicklist().then(function(nicklist) { - handlers.handleNicklist(nicklist); - }); - _requestSync(); $log.info("Connected to relay"); $rootScope.connected = true; @@ -412,6 +401,22 @@ function($rootScope, })); }; + + var requestNicklist = function(bufferId, callback) { + bufferId = bufferId || null; + ngWebsockets.send( + weeChat.Protocol.formatNicklist({ + buffer: bufferId + }) + ).then(function(nicklist) { + handlers.handleNicklist(nicklist); + if (callback !== undefined) { + callback(); + } + }); + }; + + var fetchMoreLines = function(numLines) { var buffer = models.getActiveBuffer(); // Calculate number of lines to fetch, at least as many as the parameter @@ -468,7 +473,8 @@ function($rootScope, disconnect: disconnect, sendMessage: sendMessage, sendCoreCommand: sendCoreCommand, - fetchMoreLines: fetchMoreLines + fetchMoreLines: fetchMoreLines, + requestNicklist: requestNicklist }; }]); @@ -641,15 +647,23 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', }; $rootScope.$on('activeBufferChanged', function() { - $rootScope.scrollWithBuffer(true); - var ab = models.getActiveBuffer(); + + if (ab.isNicklistEmpty()) { + var bufferId = '0x' + ab.id; // WeeChat needs the 0x prefix + connection.requestNicklist(bufferId, function() { + $scope.showNicklist = $scope.updateShowNicklist(); + }); + } + if (ab.requestedLines < $scope.lines) { // buffer has not been loaded, but some lines may already be present if they arrived after we connected $scope.fetchMoreLines($scope.lines); } $rootScope.updateTitle(ab); + $rootScope.scrollWithBuffer(true); + // If user wants to sync hotlist with weechat // we will send a /buffer bufferName command every time // the user switches a buffer. This will ensure that notifications