Skip to content

Commit

Permalink
Merge bfb1e58 into 92a35f9
Browse files Browse the repository at this point in the history
  • Loading branch information
Pchelolo committed Sep 7, 2018
2 parents 92a35f9 + bfb1e58 commit 697a082
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions sys/parsoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,24 @@ function replaceSections(original, sectionsJson) {
return `<body>${newBody}</body>`;
}

// 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);
});
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 697a082

Please sign in to comment.