From 6746de57f6338ba3922009609e2c04ef7db2ff5a Mon Sep 17 00:00:00 2001 From: MaysWind Date: Tue, 24 May 2016 22:22:47 +0800 Subject: [PATCH] reduce response size in task list page --- app/scripts/controllers/list.js | 25 ++++++++++++++++++------- app/scripts/core/utils.js | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/scripts/controllers/list.js b/app/scripts/controllers/list.js index 5368d44..47f3348 100644 --- a/app/scripts/controllers/list.js +++ b/app/scripts/controllers/list.js @@ -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]); + } } } }); diff --git a/app/scripts/core/utils.js b/app/scripts/core/utils.js index 7fe638c..274a888 100644 --- a/app/scripts/core/utils.js +++ b/app/scripts/core/utils.js @@ -27,7 +27,7 @@ }); }, 100); }, - replaceArray: function (sourceArray, targetArray, keyProperty) { + extendArray: function (sourceArray, targetArray, keyProperty) { if (!targetArray || !sourceArray || sourceArray.length != targetArray.length) { return false; }