1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-23 07:48:48 -05:00

[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
This commit is contained in:
Tankred Hase 2014-04-22 19:41:14 +02:00
parent c2ce4e73ef
commit fdd9c22144
2 changed files with 24 additions and 12 deletions

View File

@ -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);
}
};

View File

@ -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();
});
};
});