From fdd9c221447ced0d9f9440be310375440c44d094 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 22 Apr 2014 19:41:14 +0200 Subject: [PATCH] [WO-312] Fix slowness for large inbox * Fix memory leak causing iScroll to be re-initialized each time mail-list model changes * Only do $scope.$apply() when keyboard shortcuts are actually executed --- src/js/controller/mail-list.js | 27 ++++++++++++++++----------- src/js/controller/navigation.js | 9 ++++++++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/js/controller/mail-list.js b/src/js/controller/mail-list.js index 6b52512..75fc9bc 100644 --- a/src/js/controller/mail-list.js +++ b/src/js/controller/mail-list.js @@ -164,7 +164,7 @@ define(function(require) { var index = getFolder().messages.indexOf(email); // show the next mail if (getFolder().messages.length > 1) { - // if we're about to delete the last entry of the array, show the previous (i.e. the one below in the list), + // if we're about to delete the last entry of the array, show the previous (i.e. the one below in the list), // otherwise show the next one (i.e. the one above in the list) $scope.select(_.last(getFolder().messages) === email ? getFolder().messages[index - 1] : getFolder().messages[index + 1]); } else { @@ -289,6 +289,8 @@ define(function(require) { }]; // sender address this.to = [{ address: 'max.musterman@gmail.com' + }, { + address: 'max.musterman@gmail.com' }]; // list of receivers this.cc = [{ address: 'john.doe@gmail.com' @@ -403,7 +405,8 @@ define(function(require) { return { link: function(scope, elm, attrs) { var model = attrs.ngIscroll, - listEl = elm[0]; + listEl = elm[0], + myScroll; /* * iterates over the mails in the mail list and loads their bodies if they are visible in the viewport @@ -418,7 +421,7 @@ define(function(require) { isPartiallyVisibleTop, isPartiallyVisibleBottom, isVisible; for (var i = 0, len = listItems.length; i < len; i++) { - // the n-th list item (the dom representation of an email) corresponds to + // the n-th list item (the dom representation of an email) corresponds to // the n-th message model in the filteredMessages array listItem = listItems.item(i).getBoundingClientRect(); message = scope.filteredMessages[i]; @@ -439,17 +442,19 @@ define(function(require) { } }; - // re-init iScroll when model length changes - scope.$watch(model, function() { - var myScroll; - // activate iscroll - myScroll = new IScroll(listEl, { - mouseWheel: true - }); + // activate iscroll + myScroll = new IScroll(listEl, { + mouseWheel: true, + scrollbars: true, + fadeScrollbars: true + }); + myScroll.on('scrollEnd', scope.loadVisibleBodies); + // refresh iScroll when model length changes + scope.$watch(model, function() { + myScroll.refresh(); // load the visible message bodies, when the list is re-initialized and when scrolling stopped scope.loadVisibleBodies(); - myScroll.on('scrollEnd', scope.loadVisibleBodies); }, true); } }; diff --git a/src/js/controller/navigation.js b/src/js/controller/navigation.js index 1c918ee..2de2e5e 100644 --- a/src/js/controller/navigation.js +++ b/src/js/controller/navigation.js @@ -153,6 +153,7 @@ define(function(require) { // n -> new mail e.preventDefault(); scope.state.writer.write(); + scope.$apply(); } else if (modifier && e.keyCode === 70 && !scope.state.writer.open) { // f -> find @@ -161,39 +162,45 @@ define(function(require) { $timeout(function() { scope.state.mailList.searching = false; }, 200); + scope.$apply(); } else if (modifier && e.keyCode === 82 && scope.state.writer && !scope.state.writer.open && scope.state.mailList.selected) { // r -> reply e.preventDefault(); scope.state.writer.write(scope.state.mailList.selected); + scope.$apply(); } else if (modifier && e.keyCode === 83 && scope.state.writer && !scope.state.writer.open && scope.state.mailList.synchronize) { // s -> sync folder e.preventDefault(); scope.state.mailList.synchronize(); + scope.$apply(); } else if (e.keyCode === 27 && scope.state.writer.open) { // escape -> close writer e.preventDefault(); scope.state.writer.close(); + scope.$apply(); } else if (e.keyCode === 27 && scope.state.account.open) { // escape -> close account view e.preventDefault(); scope.state.account.toggle(false); + scope.$apply(); } else if (e.keyCode === 27 && scope.state.contacts.open) { // escape -> close contacts view e.preventDefault(); scope.state.contacts.toggle(false); + scope.$apply(); } else if (e.keyCode === 27 && scope.state.nav.open) { // escape -> close nav view e.preventDefault(); scope.state.nav.toggle(false); + scope.$apply(); } - scope.$apply(); }); }; });