Improved messages perf

Memory optimise
This commit is contained in:
Igor Zhukov 2015-11-29 20:50:41 +03:00
parent faaffc9b6e
commit 6d316570c6
2 changed files with 27 additions and 15 deletions

View File

@ -699,9 +699,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
dialog = $scope.dialogs[i];
if (dialogsUpdated[dialog.peerID]) {
$scope.dialogs.splice(i, 1);
AppMessagesManager.clearDialogCache($scope.dialogs.mid);
i--;
len--;
AppMessagesManager.clearDialogCache(dialog.mid);
}
}
len = indexes.length;
@ -893,8 +893,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
!AppChatsManager.hasRights(-dialog.peerID, 'send')) {
return;
}
var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog);
if (!searchMessages) {
var wrapDialog = searchMessages ? undefined : dialog;
var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, wrapDialog);
if (searchMessages) {
wrappedDialog.unreadCount = -1;
} else {
peersInDialogs[dialog.peerID] = true;
}
dialogsList.push(wrappedDialog);
@ -949,8 +952,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
!AppChatsManager.hasRights(-dialog.peerID, 'send')) {
return;
}
var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog);
if (!searchMessages) {
var wrapDialog = searchMessages ? undefined : dialog;
var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, wrapDialog);
if (searchMessages) {
wrappedDialog.unreadCount = -1;
} else {
peersInDialogs[dialog.peerID] = true;
}
dialogsList.push(wrappedDialog);
@ -1910,22 +1916,23 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}
delete $scope.state.empty;
}
if (len > 10) {
if ((!curPeer || isIDLE) &&
exlen > (len > 10 ? 10 : 10)) {
console.warn(dT(), 'Drop too many messages', len, exlen, isIDLE, curPeer, peerID);
if (curPeer) {
if (exlen > 10 && isIDLE) {
minID = history.messages[exlen - 1].mid;
$scope.historyState.skipped = hasLess = minID > 0;
if (hasLess) {
loadAfterSync = peerID;
$scope.$broadcast('ui_history_append');
return;
}
minID = history.messages[exlen - 1].mid;
$scope.historyState.skipped = hasLess = minID > 0;
if (hasLess) {
loadAfterSync = peerID;
$scope.$broadcast('ui_history_append');
}
} else {
historiesQueuePop(peerID);
return;
}
return;
}
var messageID, historyMessage, i;
var hasOut = false;
var unreadAfterNew = false;
@ -2067,6 +2074,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}
if (!newVal) {
unreadAfterIdle = false;
if (loadAfterSync == $scope.curDialog.peerID) {
loadHistory();
loadAfterSync = false;
}
}
});

View File

@ -1983,6 +1983,7 @@ angular.module('myApp.services')
if (useCache && messagesForDialogs[msgID] !== undefined) {
delete messagesForDialogs[msgID].typing;
messagesForDialogs[msgID].unreadCount = unreadCount;
return messagesForDialogs[msgID];
}