1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Move data request into controller to speed up page load

This commit is contained in:
Joe Fiorini 2015-06-05 15:42:36 -04:00
parent 65d20e646d
commit 63b7ec8b67
3 changed files with 102 additions and 135 deletions

View File

@ -9,7 +9,7 @@ export default
'getModuleOptions', 'getModuleOptions',
'resolveVersions', 'resolveVersions',
'lodashAsPromised', 'lodashAsPromised',
function(factScanDataService, getModuleOptions, resolveVersions) { function(factScanDataService, getModuleOptions, resolveVersions, _) {
return function(hostIds, moduleName, leftDate, rightDate) { return function(hostIds, moduleName, leftDate, rightDate) {
var moduleOptions; var moduleOptions;
@ -29,31 +29,28 @@ export default
} }
]; ];
return getModuleOptions(hostIds[0]) return _(hostVersionParams)
.then(function(modules) { .map(function(versionParam) {
moduleOptions = modules; var versionWithRequest =
return hostVersionParams; [ versionParam,
}).thenMap(function(versionParam) { factScanDataService.
var versionWithRequest = getVersion(versionParam)
[ versionParam, ];
factScanDataService.
getVersion(versionParam)
];
return versionWithRequest; return versionWithRequest;
}).thenAll(function(versions) { }).thenAll(function(versions) {
return resolveVersions(versions); return resolveVersions(versions);
}, true) }, true)
.thenMap(function(versionData) { .thenMap(function(versionData) {
if (versionData) { if (versionData) {
return factScanDataService.getFacts(versionData); return factScanDataService.getFacts(versionData);
} else { } else {
return { fact: [] }; return { fact: [] };
} }
}) })
.thenAll(function(hostFacts) { .thenAll(function(hostFacts) {
return [moduleOptions, hostFacts]; return [moduleOptions, hostFacts];
}); });
}; };
} }
]; ];

View File

@ -12,14 +12,16 @@ function controller($rootScope,
$routeParams, $routeParams,
$location, $location,
$q, $q,
initialFactData, moduleOptions,
getDataForComparison, getDataForComparison,
waitIndicator, waitIndicator,
moment, moment,
_) { _) {
// var inventoryId = $routeParams.id; // var inventoryId = $routeParams.id;
var hostIds = $routeParams.hosts.split(','); var hostIds = $routeParams.hosts.split(',');
var hosts = $routeParams.model.hosts; var hosts = $routeParams.model.hosts;
var moduleParam = $routeParams.module || 'packages';
$scope.hostIds = $routeParams.hosts; $scope.hostIds = $routeParams.hosts;
$scope.inventory = $routeParams.model.inventory; $scope.inventory = $routeParams.model.inventory;
@ -27,18 +29,18 @@ function controller($rootScope,
$scope.factModulePickersLabelLeft = "Compare facts collected on or before"; $scope.factModulePickersLabelLeft = "Compare facts collected on or before";
$scope.factModulePickersLabelRight = "To facts collected on or before"; $scope.factModulePickersLabelRight = "To facts collected on or before";
$scope.modules = initialFactData.moduleOptions; $scope.modules = moduleOptions;
var leftSearchRange = searchDateRange('yesterday');
var rightSearchRange = searchDateRange();
var searchConfig = var searchConfig =
{ leftRange: initialFactData.leftSearchRange, { leftRange: leftSearchRange,
rightRange: initialFactData.rightSearchRange rightRange: rightSearchRange
}; };
$scope.leftDate = initialFactData.leftSearchRange.from; $scope.leftDate = leftSearchRange.from;
$scope.rightDate = initialFactData.rightSearchRange.from; $scope.rightDate = rightSearchRange.from;
$scope.leftScanDate = initialFactData.leftScanDate;
$scope.rightScanDate = initialFactData.rightScanDate;
$scope.leftHostname = hosts[0].name; $scope.leftHostname = hosts[0].name;
$scope.rightHostname = hosts.length > 1 ? hosts[1].name : hosts[0].name; $scope.rightHostname = hosts.length > 1 ? hosts[1].name : hosts[0].name;
@ -53,91 +55,86 @@ function controller($rootScope,
var activeModule = searchConfig.module; var activeModule = searchConfig.module;
if (!factData) { waitIndicator('start');
factData =
getDataForComparison( return getDataForComparison(
hostIds, hostIds,
activeModule.name, activeModule.name,
leftRange, leftRange,
rightRange) rightRange)
.then(function(factDataAndModules) { .then(function(factDataAndModules) {
var responses = factDataAndModules[1]; var responses = factDataAndModules[1];
var data = _.pluck(responses, 'fact'); var data = _.pluck(responses, 'fact');
$scope.leftScanDate = moment(responses[0].timestamp); $scope.leftScanDate = moment(responses[0].timestamp);
$scope.rightScanDate = moment(responses[1].timestamp); $scope.rightScanDate = moment(responses[1].timestamp);
return data; return data;
}, true); })
}
waitIndicator('start'); .then(function(facts) {
// Make sure we always start comparison against
// a non-empty array
//
// Partition with _.isEmpty will give me an array
// with empty arrays in index 0, and non-empty
// arrays in index 1
//
return _(factData) // Save the position of the data so we
.promise() // don't lose it later
.then(function(facts) {
// Make sure we always start comparison against
// a non-empty array
//
// Partition with _.isEmpty will give me an array
// with empty arrays in index 0, and non-empty
// arrays in index 1
//
// Save the position of the data so we facts[0].position = 'left';
// don't lose it later facts[1].position = 'right';
facts[0].position = 'left'; var splitFacts = _.partition(facts, _.isEmpty);
facts[1].position = 'right'; var emptyScans = splitFacts[0];
var nonEmptyScans = splitFacts[1];
var result;
var splitFacts = _.partition(facts, _.isEmpty); if (_.isEmpty(nonEmptyScans)) {
var emptyScans = splitFacts[0]; // we have NO data, throw an error
var nonEmptyScans = splitFacts[1]; result = _.reject({
var result; name: 'NoScanData',
message: 'No scans ran on eithr of the dates you selected. Please try selecting different dates.',
dateValues:
{ leftDate: $scope.leftDate.clone(),
rightDate: $scope.rightDate.clone()
}
});
} else if (nonEmptyScans.length === 1) {
// one of them is not empty, throw an error
result = _.reject({
name: 'InsufficientScanData',
message: 'No scans ran on one of the selected dates. Please try selecting a different date.',
dateValue: emptyScans[0].position === 'left' ? $scope.leftDate.clone() : $scope.rightDate.clone()
});
} else {
result = _.promise(facts);
}
if (_.isEmpty(nonEmptyScans)) { delete facts[0].position;
// we have NO data, throw an error delete facts[1].position;
result = _.reject({
name: 'NoScanData',
message: 'No scans ran on eithr of the dates you selected. Please try selecting different dates.',
dateValues:
{ leftDate: $scope.leftDate.clone(),
rightDate: $scope.rightDate.clone()
}
});
} else if (nonEmptyScans.length === 1) {
// one of them is not empty, throw an error
result = _.reject({
name: 'InsufficientScanData',
message: 'No scans ran on one of the selected dates. Please try selecting a different date.',
dateValue: emptyScans[0].position === 'left' ? $scope.leftDate.clone() : $scope.rightDate.clone()
});
} else {
result = _.promise(facts);
}
delete facts[0].position; // all scans have data, rejoice!
delete facts[1].position; return result;
// all scans have data, rejoice! })
return result; .then(_.partial(compareFacts, activeModule))
.then(function(info) {
}) // Clear out any errors from the previous run...
.then(_.partial(compareFacts, activeModule)) $scope.error = null;
.then(function(info) {
// Clear out any errors from the previous run... $scope.factData = info;
$scope.error = null;
$scope.factData = info; return info;
return info; }).catch(function(error) {
$scope.error = error;
}).catch(function(error) { }).finally(function() {
$scope.error = error; waitIndicator('stop');
}).finally(function() { });
waitIndicator('stop');
});
} }
$scope.setActiveModule = function(newModuleName, initialData) { $scope.setActiveModule = function(newModuleName, initialData) {
@ -183,7 +180,7 @@ function controller($rootScope,
$scope.$watch('rightDate', dateWatcher('rightRange'), true); $scope.$watch('rightDate', dateWatcher('rightRange'), true);
$scope.setActiveModule(initialFactData.moduleName, initialFactData); $scope.setActiveModule(moduleParam);
} }
export default export default
@ -192,7 +189,7 @@ export default
'$routeParams', '$routeParams',
'$location', '$location',
'$q', '$q',
'factScanData', 'moduleOptions',
'getDataForComparison', 'getDataForComparison',
'Wait', 'Wait',
'moment', 'moment',

View File

@ -4,8 +4,6 @@
* All Rights Reserved * All Rights Reserved
*************************************************/ *************************************************/
import {searchDateRange} from './search-date-range';
import moment from 'tower/shared/moment/moment';
export default { export default {
name: 'systemTracking', name: 'systemTracking',
@ -14,41 +12,16 @@ export default {
templateUrl: '/static/js/system-tracking/system-tracking.partial.html', templateUrl: '/static/js/system-tracking/system-tracking.partial.html',
reloadOnSearch: false, reloadOnSearch: false,
resolve: { resolve: {
factScanData: moduleOptions:
[ 'getDataForComparison', [ 'getModuleOptions',
'lodashAsPromised', 'lodashAsPromised',
'$route', '$route',
'$location', function(getModuleOptions, _, $route) {
function(getDataForComparison, _, $route, $location) {
var hostIds = $route.current.params.hosts.split(','); var hostIds = $route.current.params.hosts.split(',');
var moduleParam = $location.search().module || 'packages';
var leftDate = searchDateRange('yesterday');
var rightDate = searchDateRange();
if (hostIds.length === 1) {
hostIds = hostIds.concat(hostIds[0]);
}
var data = var data =
getDataForComparison(hostIds, moduleParam, leftDate, rightDate). getModuleOptions(hostIds[0])
then(function(factDataAndModules) { .value();
var moduleOptions = factDataAndModules[0];
var factResponses = factDataAndModules[1];
var factData = _.pluck(factResponses, 'fact');
factData.leftSearchRange = leftDate;
factData.rightSearchRange = rightDate;
factData.leftScanDate = moment(factResponses[0].timestamp);
factData.rightScanDate = moment(factResponses[1].timestamp);
factData.moduleName = moduleParam;
factData.moduleOptions = moduleOptions;
return factData;
}, true)
.value();
return data; return data;