reduce response size in task list page

This commit is contained in:
MaysWind 2016-05-24 22:22:47 +08:00
parent baf4561edb
commit 6746de57f6
2 changed files with 19 additions and 8 deletions

View file

@ -4,6 +4,7 @@
angular.module('ariaNg').controller('DownloadListController', ['$scope', '$window', '$location', '$interval', 'translateFilter', 'aria2RpcService', 'ariaNgSettingService', 'utils', function ($scope, $window, $location, $interval, translateFilter, aria2RpcService, ariaNgSettingService, utils) {
var location = $location.path().substring(1);
var downloadTaskRefreshPromise = null;
var needRequestWholeInfo = true;
var getTitleWidth = function () {
var titleColumn = angular.element('#task-table > .row > .col-md-8:first-child');
@ -31,12 +32,15 @@
'uploadSpeed',
'downloadSpeed',
'connections',
'files',
'bittorrent',
'numSeeders',
'seeder'
];
if (needRequestWholeInfo) {
requestParams.push('files');
requestParams.push('bittorrent');
}
if (location == 'downloading') {
invokeMethod = aria2RpcService.tellActive;
params = [requestParams];
@ -52,14 +56,21 @@
return invokeMethod({
params: params,
callback: function (result) {
if (result && result.length > 0) {
for (var i = 0; i < result.length; i++) {
utils.processDownloadTask(result[i]);
if (!utils.extendArray(result, $scope.downloadTasks, 'gid')) {
if (needRequestWholeInfo) {
$scope.downloadTasks = result;
needRequestWholeInfo = false;
} else {
needRequestWholeInfo = true;
}
} else {
needRequestWholeInfo = false;
}
if (!utils.replaceArray(result, $scope.downloadTasks, 'gid')) {
$scope.downloadTasks = result;
if ($scope.downloadTasks && $scope.downloadTasks.length > 0) {
for (var i = 0; i < $scope.downloadTasks.length; i++) {
utils.processDownloadTask($scope.downloadTasks[i]);
}
}
}
});

View file

@ -27,7 +27,7 @@
});
}, 100);
},
replaceArray: function (sourceArray, targetArray, keyProperty) {
extendArray: function (sourceArray, targetArray, keyProperty) {
if (!targetArray || !sourceArray || sourceArray.length != targetArray.length) {
return false;
}