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');
|
||||
|
||||
function StatsBackend(rendererCache) {
|
||||
this.rendererCache = rendererCache;
|
||||
function 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 layerMetadataEnabled = enabledFeatures ? enabledFeatures.layerMetadata : false;
|
||||
var layerStats;
|
||||
if (layerMetadataEnabled) {
|
||||
layerStats = windshaftStats();
|
||||
layerStats.getStats(this.rendererCache, params, dbConnection, mapConfigProvider, callback);
|
||||
var layerStatsEnabled = enabledFeatures ? enabledFeatures.layerStats: false;
|
||||
if (layerMetadataEnabled && layerStatsEnabled) {
|
||||
var layerStats = windshaftStats();
|
||||
layerStats.getStats(mapConfig, params, dbConnection, callback);
|
||||
} else {
|
||||
layerStats = windshaftStats('torque');
|
||||
layerStats.getStats(this.rendererCache, params, dbConnection, mapConfigProvider, callback);
|
||||
callback(null, null);
|
||||
}
|
||||
};
|
||||
|
@ -19,7 +19,7 @@ var NamedMapsCacheEntry = require('../cache/model/named_maps_entry');
|
||||
|
||||
var NamedMapMapConfigProvider = require('../models/mapconfig/provider/named-map-provider');
|
||||
var CreateLayergroupMapConfigProvider = require('../models/mapconfig/provider/create-layergroup-provider');
|
||||
var DummyMapConfigProvider = require('../models/mapconfig/provider/dummy-mapconfig-provider');
|
||||
|
||||
|
||||
/**
|
||||
* @param {AuthApi} authApi
|
||||
@ -364,30 +364,18 @@ function(req, res, mapconfig, layergroup, analysesResults, rendererParams, callb
|
||||
|
||||
return null;
|
||||
},
|
||||
function fetchLayersMetadata(err) {
|
||||
function fetchLayersStats(err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
var mapConfigProvider = new DummyMapConfigProvider(mapconfig, rendererParams);
|
||||
self.statsBackend.getStats(rendererParams, dbConnection, mapConfigProvider, function(err, layersStats) {
|
||||
self.statsBackend.getStats(mapconfig, rendererParams, dbConnection, function(err, layersStats) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (layersStats) {
|
||||
layergroup.metadata = layergroup.metadata || {};
|
||||
layergroup.metadata.layers = layersStats;
|
||||
|
||||
// backwards compatibility for torque
|
||||
var torqueMetadata = layersStats.reduce(function(acc, layer, layerId) {
|
||||
if (layer.type === 'torque') {
|
||||
acc[layerId] = layer.meta;
|
||||
layergroup.metadata.layers.forEach(function (layer, index) {
|
||||
layer.meta.stats = layersStats[index];
|
||||
});
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
if (Object.keys(torqueMetadata).length) {
|
||||
layergroup.metadata.torque = torqueMetadata;
|
||||
}
|
||||
}
|
||||
|
||||
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 statsBackend = new StatsBackend(rendererCache);
|
||||
var statsBackend = new StatsBackend();
|
||||
|
||||
var layergroupAffectedTablesCache = new LayergroupAffectedTablesCache();
|
||||
app.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
|
||||
|
@ -6,11 +6,14 @@ var TestClient = require('../../support/test-client');
|
||||
describe('Create mapnik layergroup', function() {
|
||||
before(function() {
|
||||
this.layerMetadataConfig = global.environment.enabledFeatures.layerMetadata;
|
||||
this.layerStatsConfig = global.environment.enabledFeatures.layerStats;
|
||||
global.environment.enabledFeatures.layerMetadata = true;
|
||||
global.environment.enabledFeatures.layerStats = true;
|
||||
});
|
||||
|
||||
after(function() {
|
||||
global.environment.enabledFeatures.layerMetadata = this.layerMetadataConfig;
|
||||
global.environment.enabledFeatures.layerStats = this.layerStatsConfig;
|
||||
});
|
||||
|
||||
var cartocssVersion = '2.3.0';
|
||||
|
@ -6,11 +6,15 @@ var TestClient = require('../../support/test-client');
|
||||
describe('multilayer stats disabled', 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 () {
|
||||
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);
|
||||
layergroup.metadata.layers.forEach(function (layer) {
|
||||
if (layer.type !== 'torque' && layer.type !== 'mapnik') {
|
||||
assert.ok('stats' in layer.meta);
|
||||
assert.ok(!('stats' in layer.meta));
|
||||
} else if (layer.type !== 'torque') {
|
||||
assert.ok('stats' in layer.meta);
|
||||
assert.ok(!('stats' in layer.meta));
|
||||
assert.ok('cartocss' in layer.meta);
|
||||
} else {
|
||||
assert.ok('cartocss' in layer.meta);
|
||||
|
Loading…
Reference in New Issue
Block a user