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.
This commit is contained in:
Simon Cooksey 2016-11-04 14:20:38 +00:00
parent 03af5d7158
commit d9b86d28a0

View file

@ -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