From bfb1e5854f00de36a8212d5d1aee019c4b76273d Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Fri, 7 Sep 2018 13:15:54 -0700 Subject: [PATCH] Do not emit the dependency update event for non-latest rerenders. Bug: T203823 Change-Id: I8a83dd4ca09001f6511c7ccd0a6ca31694ea4bf5 --- sys/parsoid.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/sys/parsoid.js b/sys/parsoid.js index a9e972aea..006f17c62 100644 --- a/sys/parsoid.js +++ b/sys/parsoid.js @@ -138,19 +138,24 @@ function replaceSections(original, sectionsJson) { return `${newBody}`; } -// HTML resource_change event emission -function _dependenciesUpdate(hyper, req) { +/** HTML resource_change event emission + * hyper {HyperSwitch} the hyperswitch router object + * req {Object} the request + * [oldContent] {boolean} whether this is an older revision + */ +function _dependenciesUpdate(hyper, req, oldContent) { const rp = req.params; return mwUtil.getSiteInfo(hyper, req) .then((siteInfo) => { const baseUri = siteInfo.baseUri.replace(/^https?:/, ''); const publicURI = `${baseUri}/page/html/${encodeURIComponent(rp.title)}`; + const body = [ { meta: { uri: publicURI } } ]; + if (!oldContent) { + body.push({ meta: { uri: `${publicURI}/${rp.revision}` } }); + } return hyper.post({ uri: new URI([rp.domain, 'sys', 'events', '']), - body: [ - { meta: { uri: publicURI } }, - { meta: { uri: `${publicURI}/${rp.revision}` } } - ] + body }).catch((e) => { hyper.logger.log('warn/bg-updates', e); }); @@ -376,9 +381,12 @@ class ParsoidService { body: res.body[format].body }; resp.headers.etag = mwUtil.makeETag(rp.revision, tid); + let oldContent = false; return this.saveParsoidResultToLatest(hyper, req, tid, res) - .catch({ status: 412 }, () => - this.saveParsoidResultToFallback(hyper, req, tid, res)) + .catch({ status: 412 }, () => { + oldContent = true; + return this.saveParsoidResultToFallback(hyper, req, tid, res); + }) .then(() => { // Extract redirect target, if any const redirectTarget = mwUtil.extractRedirect(res.body.html.body); @@ -402,7 +410,7 @@ class ParsoidService { } }) .then(() => { - const dependencyUpdate = _dependenciesUpdate(hyper, req); + const dependencyUpdate = _dependenciesUpdate(hyper, req, oldContent); if (mwUtil.isNoCacheRequest(req)) { // Finish background updates before returning return dependencyUpdate.thenReturn(resp);