perf(mail(js)): delay instantiation of Message objects on load
parent
e66ad698fd
commit
bc58bd1cb0
|
@ -961,19 +961,16 @@
|
||||||
this.$futureMailboxData.then(function(data) {
|
this.$futureMailboxData.then(function(data) {
|
||||||
var selectedMessages = _.map(_this.$selectedMessages(), 'uid');
|
var selectedMessages = _.map(_this.$selectedMessages(), 'uid');
|
||||||
Mailbox.$timeout(function() {
|
Mailbox.$timeout(function() {
|
||||||
var uids, headers;
|
var uids, headers, headersFields;
|
||||||
|
|
||||||
if (!data.uids || _this.$topIndex > data.uids.length - 1)
|
if (!data.uids || _this.$topIndex > data.uids.length - 1)
|
||||||
_this.$topIndex = 0;
|
_this.$topIndex = 0;
|
||||||
|
|
||||||
_this.init(data);
|
if (data.uids) {
|
||||||
|
// Initialization phase, we received complete list of UIDs
|
||||||
|
Mailbox.$log.debug('unwrapping ' + data.uids.length + ' messages');
|
||||||
|
|
||||||
if (_this.uids) {
|
_this.init(data);
|
||||||
Mailbox.$log.debug('unwrapping ' + _this.uids.length + ' messages');
|
|
||||||
|
|
||||||
// First entry of 'headers' are keys
|
|
||||||
headers = _.invokeMap(_this.headers[0], 'toLowerCase');
|
|
||||||
_this.headers.splice(0, 1);
|
|
||||||
|
|
||||||
// First entry of 'uids' are keys when threaded view is enabled
|
// First entry of 'uids' are keys when threaded view is enabled
|
||||||
if (_this.threaded) {
|
if (_this.threaded) {
|
||||||
|
@ -981,9 +978,9 @@
|
||||||
_this.uids.splice(0, 1);
|
_this.uids.splice(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instanciate Message objects
|
// Populate $messages with object literals
|
||||||
_.reduce(_this.uids, function(msgs, msg, i) {
|
_.reduce(_this.uids, function(msgs, msg, i) {
|
||||||
var data, msgObject;
|
var data;
|
||||||
if (_this.threaded) {
|
if (_this.threaded) {
|
||||||
data = _.zipObject(uids, msg);
|
data = _.zipObject(uids, msg);
|
||||||
if (data.first === 1) {
|
if (data.first === 1) {
|
||||||
|
@ -1006,28 +1003,38 @@
|
||||||
// Build map of UID <=> index
|
// Build map of UID <=> index
|
||||||
_this.uidsMap[data.uid] = i;
|
_this.uidsMap[data.uid] = i;
|
||||||
|
|
||||||
msgObject = new Mailbox.$Message(_this.$account.id, _this, data, true);
|
|
||||||
|
|
||||||
// Restore selection
|
// Restore selection
|
||||||
msgObject.selected = selectedMessages.indexOf(msgObject.uid) > -1;
|
data.selected = selectedMessages.indexOf(data.uid) > -1;
|
||||||
|
|
||||||
msgs.push(msgObject);
|
// Add an object literal to be used later to create a Message object
|
||||||
|
msgs.push(data);
|
||||||
|
|
||||||
return msgs;
|
return msgs;
|
||||||
}, _this.$messages);
|
}, _this.$messages);
|
||||||
|
}
|
||||||
|
|
||||||
// Extend Message objects with received headers
|
if (data.headers) {
|
||||||
_.forEach(_this.headers, function(data) {
|
// First entry of 'headers' are keys
|
||||||
var msg = _.zipObject(headers, data),
|
headersFields = _.invokeMap(data.headers.splice(0, 1)[0], 'toLowerCase');
|
||||||
|
headers = data.headers;
|
||||||
|
|
||||||
|
// Instanciate or extend Message objects with received headers
|
||||||
|
_.forEach(headers, function(data) {
|
||||||
|
var msg = _.zipObject(headersFields, data),
|
||||||
i = _this.uidsMap[msg.uid.toString()];
|
i = _this.uidsMap[msg.uid.toString()];
|
||||||
|
if (!(_this.$messages[i] instanceof Mailbox.$Message)) {
|
||||||
|
_this.$messages[i] = new Mailbox.$Message(_this.$account.id, _this, _this.$messages[i], true);
|
||||||
|
}
|
||||||
_this.$messages[i].init(msg);
|
_this.$messages[i].init(msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Mailbox.$log.debug('mailbox ' + _this.id + ' ready');
|
Mailbox.$log.debug('mailbox ' + _this.id + ' ready');
|
||||||
_this.$isLoading = false;
|
_this.$isLoading = false;
|
||||||
deferred.resolve(_this.$messages);
|
deferred.resolve(_this.$messages);
|
||||||
});
|
});
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
|
Mailbox.$log.error(data);
|
||||||
angular.extend(_this, data);
|
angular.extend(_this, data);
|
||||||
_this.isError = true;
|
_this.isError = true;
|
||||||
_this.$isLoading = false;
|
_this.$isLoading = false;
|
||||||
|
@ -1057,6 +1064,9 @@
|
||||||
messageHeaders = _.zipObject(headers, messageHeaders);
|
messageHeaders = _.zipObject(headers, messageHeaders);
|
||||||
j = _this.uidsMap[messageHeaders.uid.toString()];
|
j = _this.uidsMap[messageHeaders.uid.toString()];
|
||||||
if (angular.isDefined(j)) {
|
if (angular.isDefined(j)) {
|
||||||
|
if (!(_this.$messages[j] instanceof Mailbox.$Message)) {
|
||||||
|
_this.$messages[j] = new Mailbox.$Message(_this.$account.id, _this, _this.$messages[j], true);
|
||||||
|
}
|
||||||
_this.$messages[j].init(messageHeaders);
|
_this.$messages[j].init(messageHeaders);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue