From d9b86d28a00960120707def46f90fb0c3097bd6e Mon Sep 17 00:00:00 2001 From: Simon Cooksey Date: Fri, 4 Nov 2016 14:20:38 +0000 Subject: [PATCH] Added cap on max number of unread lines to load This is to improve performance when switching to a buffer with a large number of unread lines. Fixes #859 Thanks to @lorenzhs for the comments on PR #862. --- js/glowingbear.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 753085d..d5d7a7b 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -145,11 +145,9 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $rootScope.$on('activeBufferChanged', function(event, unreadSum) { var ab = models.getActiveBuffer(); - // Discard surplus lines. This is done *before* lines are fetched because that saves us the effort of special handling for the - // case where a buffer is opened for the first time ;) - var minRetainUnread = ab.lines.length - unreadSum + 5; // do not discard unread lines and keep 5 additional lines for context - var surplusLines = ab.lines.length - (2 * $scope.lines_per_screen + 10); // retain up to 2*(screenful + 10) + 10 lines because magic numbers - var linesToRemove = Math.min(minRetainUnread, surplusLines); + // Discard unread lines above 2 screenfuls. We can click through to get more if needs be + // This is to keep GB responsive when loading buffers which have seen a lot of traffic. See issue #859 + var linesToRemove = ab.lines.length - (2 * $scope.lines_per_screen + 10); if (linesToRemove > 0) { ab.lines.splice(0, linesToRemove); // remove the lines from the buffer