Stats backend only provides stats not metadata
This commit is contained in:
parent
7d5b6b0820
commit
daf19c5e27
@ -1,20 +1,18 @@
|
|||||||
var windshaftStats = require('windshaft-stats');
|
var windshaftStats = require('windshaft-stats');
|
||||||
|
|
||||||
function StatsBackend(rendererCache) {
|
function StatsBackend() {
|
||||||
this.rendererCache = rendererCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = StatsBackend;
|
module.exports = StatsBackend;
|
||||||
|
|
||||||
StatsBackend.prototype.getStats = function(params, dbConnection, mapConfigProvider, callback) {
|
StatsBackend.prototype.getStats = function(mapConfig, params, dbConnection, callback) {
|
||||||
var enabledFeatures = global.environment.enabledFeatures;
|
var enabledFeatures = global.environment.enabledFeatures;
|
||||||
var layerMetadataEnabled = enabledFeatures ? enabledFeatures.layerMetadata : false;
|
var layerMetadataEnabled = enabledFeatures ? enabledFeatures.layerMetadata : false;
|
||||||
var layerStats;
|
var layerStatsEnabled = enabledFeatures ? enabledFeatures.layerStats: false;
|
||||||
if (layerMetadataEnabled) {
|
if (layerMetadataEnabled && layerStatsEnabled) {
|
||||||
layerStats = windshaftStats();
|
var layerStats = windshaftStats();
|
||||||
layerStats.getStats(this.rendererCache, params, dbConnection, mapConfigProvider, callback);
|
layerStats.getStats(mapConfig, params, dbConnection, callback);
|
||||||
} else {
|
} else {
|
||||||
layerStats = windshaftStats('torque');
|
callback(null, null);
|
||||||
layerStats.getStats(this.rendererCache, params, dbConnection, mapConfigProvider, callback);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@ var NamedMapsCacheEntry = require('../cache/model/named_maps_entry');
|
|||||||
|
|
||||||
var NamedMapMapConfigProvider = require('../models/mapconfig/provider/named-map-provider');
|
var NamedMapMapConfigProvider = require('../models/mapconfig/provider/named-map-provider');
|
||||||
var CreateLayergroupMapConfigProvider = require('../models/mapconfig/provider/create-layergroup-provider');
|
var CreateLayergroupMapConfigProvider = require('../models/mapconfig/provider/create-layergroup-provider');
|
||||||
var DummyMapConfigProvider = require('../models/mapconfig/provider/dummy-mapconfig-provider');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {AuthApi} authApi
|
* @param {AuthApi} authApi
|
||||||
@ -364,30 +364,18 @@ function(req, res, mapconfig, layergroup, analysesResults, rendererParams, callb
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
function fetchLayersMetadata(err) {
|
function fetchLayersStats(err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
var next = this;
|
var next = this;
|
||||||
var mapConfigProvider = new DummyMapConfigProvider(mapconfig, rendererParams);
|
self.statsBackend.getStats(mapconfig, rendererParams, dbConnection, function(err, layersStats) {
|
||||||
self.statsBackend.getStats(rendererParams, dbConnection, mapConfigProvider, function(err, layersStats) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
if (layersStats) {
|
if (layersStats) {
|
||||||
layergroup.metadata = layergroup.metadata || {};
|
layergroup.metadata.layers.forEach(function (layer, index) {
|
||||||
layergroup.metadata.layers = layersStats;
|
layer.meta.stats = layersStats[index];
|
||||||
|
});
|
||||||
// backwards compatibility for torque
|
|
||||||
var torqueMetadata = layersStats.reduce(function(acc, layer, layerId) {
|
|
||||||
if (layer.type === 'torque') {
|
|
||||||
acc[layerId] = layer.meta;
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
if (Object.keys(torqueMetadata).length) {
|
|
||||||
layergroup.metadata.torque = torqueMetadata;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
var util = require('util');
|
|
||||||
var MapStoreMapConfigProvider = require('windshaft').model.provider.MapStoreMapConfig;
|
|
||||||
|
|
||||||
function DummyMapConfigProvider(mapConfig, params) {
|
|
||||||
MapStoreMapConfigProvider.call(this, undefined, params);
|
|
||||||
|
|
||||||
this.mapConfig = mapConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
util.inherits(DummyMapConfigProvider, MapStoreMapConfigProvider);
|
|
||||||
|
|
||||||
module.exports = DummyMapConfigProvider;
|
|
||||||
|
|
||||||
DummyMapConfigProvider.prototype.setParams = function(params) {
|
|
||||||
this.params = params;
|
|
||||||
};
|
|
||||||
|
|
||||||
DummyMapConfigProvider.prototype.getMapConfig = function(callback) {
|
|
||||||
return callback(null, this.mapConfig, this.params, {});
|
|
||||||
};
|
|
@ -152,7 +152,7 @@ module.exports = function(serverOptions) {
|
|||||||
|
|
||||||
var analysisBackend = new AnalysisBackend(metadataBackend, serverOptions.analysis);
|
var analysisBackend = new AnalysisBackend(metadataBackend, serverOptions.analysis);
|
||||||
|
|
||||||
var statsBackend = new StatsBackend(rendererCache);
|
var statsBackend = new StatsBackend();
|
||||||
|
|
||||||
var layergroupAffectedTablesCache = new LayergroupAffectedTablesCache();
|
var layergroupAffectedTablesCache = new LayergroupAffectedTablesCache();
|
||||||
app.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
|
app.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
|
||||||
|
@ -6,11 +6,14 @@ var TestClient = require('../../support/test-client');
|
|||||||
describe('Create mapnik layergroup', function() {
|
describe('Create mapnik layergroup', function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
this.layerMetadataConfig = global.environment.enabledFeatures.layerMetadata;
|
this.layerMetadataConfig = global.environment.enabledFeatures.layerMetadata;
|
||||||
|
this.layerStatsConfig = global.environment.enabledFeatures.layerStats;
|
||||||
global.environment.enabledFeatures.layerMetadata = true;
|
global.environment.enabledFeatures.layerMetadata = true;
|
||||||
|
global.environment.enabledFeatures.layerStats = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function() {
|
after(function() {
|
||||||
global.environment.enabledFeatures.layerMetadata = this.layerMetadataConfig;
|
global.environment.enabledFeatures.layerMetadata = this.layerMetadataConfig;
|
||||||
|
global.environment.enabledFeatures.layerStats = this.layerStatsConfig;
|
||||||
});
|
});
|
||||||
|
|
||||||
var cartocssVersion = '2.3.0';
|
var cartocssVersion = '2.3.0';
|
||||||
|
@ -6,11 +6,15 @@ var TestClient = require('../../support/test-client');
|
|||||||
describe('multilayer stats disabled', function() {
|
describe('multilayer stats disabled', function() {
|
||||||
|
|
||||||
before(function () {
|
before(function () {
|
||||||
global.environment.enabledFeatures.layerMetadata = false;
|
this.layerMetadataConfig = global.environment.enabledFeatures.layerMetadata;
|
||||||
|
this.layerStatsConfig = global.environment.enabledFeatures.layerStats;
|
||||||
|
global.environment.enabledFeatures.layerMetadata = true;
|
||||||
|
global.environment.enabledFeatures.layerStats = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
global.environment.enabledFeatures.layerMetadata = true;
|
global.environment.enabledFeatures.layerMetadata = this.layerMetadataConfig;
|
||||||
|
global.environment.enabledFeatures.layerStats = this.layerStatsConfig;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -28,9 +32,9 @@ describe('multilayer stats disabled', function() {
|
|||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
layergroup.metadata.layers.forEach(function (layer) {
|
layergroup.metadata.layers.forEach(function (layer) {
|
||||||
if (layer.type !== 'torque' && layer.type !== 'mapnik') {
|
if (layer.type !== 'torque' && layer.type !== 'mapnik') {
|
||||||
assert.ok('stats' in layer.meta);
|
assert.ok(!('stats' in layer.meta));
|
||||||
} else if (layer.type !== 'torque') {
|
} else if (layer.type !== 'torque') {
|
||||||
assert.ok('stats' in layer.meta);
|
assert.ok(!('stats' in layer.meta));
|
||||||
assert.ok('cartocss' in layer.meta);
|
assert.ok('cartocss' in layer.meta);
|
||||||
} else {
|
} else {
|
||||||
assert.ok('cartocss' in layer.meta);
|
assert.ok('cartocss' in layer.meta);
|
||||||
|
Loading…
Reference in New Issue
Block a user