Inline method to set cache-cannel, rollback extract setCacheChannel method

This commit is contained in:
Daniel García Aubert 2017-11-13 12:15:12 +01:00
parent 6f59c61c8b
commit 590233e3ee

View File

@ -386,6 +386,8 @@ LayergroupController.prototype.staticMap = function(req, res, width, height, zoo
};
LayergroupController.prototype.sendResponse = function(req, res, body, status, headers) {
var self = this;
req.profiler.done('res');
res.set('Cache-Control', 'public,max-age=31536000');
@ -400,48 +402,42 @@ LayergroupController.prototype.sendResponse = function(req, res, body, status, h
}
res.set('Last-Modified', lastUpdated.toUTCString());
this.setCacheChannel(req, res, (err) => {
if (err) {
global.logger.warn('ERROR generating cache channel: ' + err);
}
if (headers) {
res.set(headers);
}
res.status(status);
if (!Buffer.isBuffer(body) && typeof body === 'object') {
if (req.query && req.query.callback) {
res.jsonp(body);
} else {
res.json(body);
var dbName = res.locals.dbname;
step(
function getAffectedTables() {
self.getAffectedTables(res.locals.user, dbName, res.locals.token, this);
},
function sendResponse(err, affectedTables) {
req.profiler.done('affectedTables');
if (err) {
global.logger.warn('ERROR generating cache channel: ' + err);
}
if (!!affectedTables) {
res.set('X-Cache-Channel', affectedTables.getCacheChannel());
self.surrogateKeysCache.tag(res, affectedTables);
}
if (headers) {
res.set(headers);
}
res.status(status);
if (!Buffer.isBuffer(body) && typeof body === 'object') {
if (req.query && req.query.callback) {
res.jsonp(body);
} else {
res.json(body);
}
} else {
res.send(body);
}
} else {
res.send(body);
}
});
};
LayergroupController.prototype.setCacheChannel = function(req, res, callback) {
const { dbname, user, token } = res.locals;
this.getAffectedTables(user, dbname, token, (err, affectedTables) => {
req.profiler.done('affectedTables');
if (err) {
return callback(err);
}
if (!!affectedTables) {
res.set('X-Cache-Channel', affectedTables.getCacheChannel());
this.surrogateKeysCache.tag(res, affectedTables);
}
callback();
});
);
};
LayergroupController.prototype.getAffectedTables = function(user, dbName, layergroupId, callback) {
if (this.layergroupAffectedTables.hasAffectedTables(dbName, layergroupId)) {
return callback(null, this.layergroupAffectedTables.get(dbName, layergroupId));
}