refactor: polishing OpenTSDB related PR #1646, added caching of aggregators request so only one call is made

This commit is contained in:
Torkel Ödegaard
2015-09-23 09:17:37 +02:00
parent 0e0caabf7d
commit 5c55617585
2 changed files with 12 additions and 11 deletions

View File

@@ -175,14 +175,17 @@ function (angular, _, dateMath) {
});
};
OpenTSDBDatasource.prototype.performAggregatorsQuery = function() {
return this._get('/api/aggregators', {}).then(function(result) {
if (result.data instanceof Array) {
var aggregatorsPromise = null;
OpenTSDBDatasource.prototype.getAggregators = function() {
if (aggregatorsPromise) { return aggregatorsPromise; }
aggregatorsPromise = this._get('/api/aggregators').then(function(result) {
if (result.data && _.isArray(result.data)) {
return result.data.sort();
} else {
return result.data;
}
return [];
});
return aggregatorsPromise;
};
function transformMetricData(md, groupByTags, target, options) {

View File

@@ -14,12 +14,6 @@ function (angular, _, kbn) {
$scope.target.errors = validateTarget($scope.target);
$scope.aggregators = ['avg', 'sum', 'min', 'max', 'dev', 'zimsum', 'mimmin', 'mimmax'];
$scope.datasource.performAggregatorsQuery().then(function(result) {
if (result) {
$scope.aggregators = result;
}
});
if (!$scope.target.aggregator) {
$scope.target.aggregator = 'sum';
}
@@ -27,6 +21,10 @@ function (angular, _, kbn) {
if (!$scope.target.downsampleAggregator) {
$scope.target.downsampleAggregator = 'avg';
}
$scope.datasource.getAggregators().then(function(aggs) {
$scope.aggregators = aggs;
});
};
$scope.targetBlur = function() {