From 325bdfe92ffe51b2a733c1638942f66a9e703b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 20 Mar 2018 09:34:06 +0100 Subject: [PATCH] Move middleware --- lib/cartodb/controllers/map.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index 8022c7a2..61d42ed4 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -89,6 +89,7 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal augmentLayergroupData(), getAffectedTables(this.pgConnection, this.layergroupAffectedTables), setCacheChannel(), + setSurrogateKeyHeader(this.surrogateKeysCache), setLastModified(), setLastUpdatedTimeToLayergroup(), setCacheControl(), @@ -99,7 +100,6 @@ MapController.prototype.composeCreateMapMiddleware = function (useTemplate = fal setTurboCartoMetadataToLayergroup(this.layergroupMetadata), setAggregationMetadataToLayergroup(this.layergroupMetadata), setTilejsonMetadataToLayergroup(this.layergroupMetadata), - setSurrogateKeyHeader(this.surrogateKeysCache), sendResponse(), augmentError({ label, addContext }) ]; @@ -393,6 +393,22 @@ function setCacheChannel () { }; } +function setSurrogateKeyHeader (surrogateKeysCache) { + return function setSurrogateKeyHeaderMiddleware(req, res, next) { + const { affectedTables, user, templateName } = res.locals; + + if (req.method === 'GET' && affectedTables.tables && affectedTables.tables.length > 0) { + surrogateKeysCache.tag(res, affectedTables); + } + + if (templateName) { + surrogateKeysCache.tag(res, new NamedMapsCacheEntry(user, templateName)); + } + + next(); + }; +} + function setLastModified () { return function setLastModifiedMiddleware (req, res, next) { if (req.method === 'GET') { @@ -542,22 +558,6 @@ function setTilejsonMetadataToLayergroup (layergroupMetadata) { }; } -function setSurrogateKeyHeader (surrogateKeysCache) { - return function setSurrogateKeyHeaderMiddleware(req, res, next) { - const { affectedTables, user, templateName } = res.locals; - - if (req.method === 'GET' && affectedTables.tables && affectedTables.tables.length > 0) { - surrogateKeysCache.tag(res, affectedTables); - } - - if (templateName) { - surrogateKeysCache.tag(res, new NamedMapsCacheEntry(user, templateName)); - } - - next(); - }; -} - function augmentError (options) { const { addContext = false, label = 'MAPS CONTROLLER' } = options;