[MediaWiki-commits] [Gerrit] mediawiki...parsoid[master]: Slowly start to wean us off using parser env in http api routes
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/395583 ) Change subject: Slowly start to wean us off using parser env in http api routes .. Slowly start to wean us off using parser env in http api routes Change-Id: I55cb78bb09198cf419409c4802f8492adac25aea --- M lib/api/apiUtils.js M lib/api/internal.js M lib/api/routes.js M lib/parse.js 4 files changed, 22 insertions(+), 23 deletions(-) Approvals: Subramanya Sastry: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/api/apiUtils.js b/lib/api/apiUtils.js index c919a76..bdc85d2 100644 --- a/lib/api/apiUtils.js +++ b/lib/api/apiUtils.js @@ -166,9 +166,9 @@ env.log('fatal/request', err); }; -apiUtils.logTime = function(env, res, str) { - env.log('info', util.format( - 'completed %s in %s ms', str, Date.now() - res.locals.start +apiUtils.logTime = function(processLogger, res, str) { + processLogger.log('info', util.format( + 'completed %s in %sms', str, Date.now() - res.locals.start )); }; diff --git a/lib/api/internal.js b/lib/api/internal.js index 2bfb57e..0823b83 100644 --- a/lib/api/internal.js +++ b/lib/api/internal.js @@ -48,7 +48,7 @@ var rtResponse = function(env, req, res, data) { apiUtils.renderResponse(res, 'roundtrip', data); - apiUtils.logTime(env, res, 'parsing'); + env.log('info', 'completed in ' + (Date.now() - res.locals.start) + 'ms'); }; module.exports = function(parsoidConfig, processLogger) { diff --git a/lib/api/routes.js b/lib/api/routes.js index 260185f..d830061 100644 --- a/lib/api/routes.js +++ b/lib/api/routes.js @@ -198,7 +198,7 @@ // Validate and set the content version if (!apiUtils.validateAndSetContentVersion(res, acceptableTypes)) { - if (env.conf.parsoid.strictAcceptCheck) { + if (parsoidConfig.strictAcceptCheck) { var text = env.availableVersions.reduce(function(prev, curr) { return prev + apiUtils[opts.format + 'ContentType'](env, curr) + '\n'; }, 'Not acceptable.\n'); @@ -283,15 +283,9 @@ }); } - p = p.tap(function() { - env.bumpParserResourceUse('wikitextSize', - (typeof wt !== 'string' ? env.page.src : wt).length); - }); - var doSubst = (typeof wt === 'string' && res.locals.subst); if (doSubst) { p = p.then(function(wikitext) { - // FIXME: reset limits after subst'ing return apiUtils.substTopLevelTemplates(env, target, wikitext); }); } @@ -306,7 +300,7 @@ } // Follow redirects if asked - if (env.conf.parsoid.devAPI && req.query.follow_redirects) { + if (parsoidConfig.devAPI && req.query.follow_redirects) { // Get localized redirect matching regexp var reSrc = env.conf.wiki.getMagicWordMatcher('redirect').source; reSrc = '^[ \\t\\n\\r\\0\\x0b]*' + @@ -321,7 +315,7 @@ } } - env.log('info', 'started parsing'); + processLogger.log('info', 'started parsing'); var envOptions = Object.assign({ pageBundle: pageBundle, @@ -407,7 +401,7 @@ } metrics.endTiming('wt2html.total', startTimers.get('wt2html.total')); } - apiUtils.logTime(env, res, 'parsing'); + apiUtils.logTime(processLogger, res, 'parsing'); }); }); }); @@ -423,8 +417,7 @@ // Performance Timing options var startTimers = new Map(); - env.bumpSerializerResourceUse('htmlSize', html.length); - env.log('info', 'started serializing'); + processLogger.log('info', 'started serializing'); if (metrics) { startTimers.set('html2wt.init', Date.now()); @@ -524,7 +517,7 @@ //clean round-tripping of HTML retrieved earlier with" // So, no oldid => no selser var hasOldId = !!res.locals.oldid; - var useSelser = hasOldId && env.conf.parsoid.useSelser; + var useSelser = hasOldId && parsoidConfig.useSelser; var selser;
[MediaWiki-commits] [Gerrit] mediawiki...parsoid[master]: Slowly start to wean us off using parser env in http api routes
Arlolra has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/395583 ) Change subject: Slowly start to wean us off using parser env in http api routes .. Slowly start to wean us off using parser env in http api routes * The pageName change is because title is not optional in v3 so it had no effect. * Also, reduce noise in mocha testing by bumping the logger level to warn. Change-Id: I55cb78bb09198cf419409c4802f8492adac25aea --- M lib/api/apiUtils.js M lib/api/internal.js M lib/api/routes.js M lib/parse.js M tests/serviceWrapper.js 5 files changed, 22 insertions(+), 32 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/83/395583/1 diff --git a/lib/api/apiUtils.js b/lib/api/apiUtils.js index c919a76..bdc85d2 100644 --- a/lib/api/apiUtils.js +++ b/lib/api/apiUtils.js @@ -166,9 +166,9 @@ env.log('fatal/request', err); }; -apiUtils.logTime = function(env, res, str) { - env.log('info', util.format( - 'completed %s in %s ms', str, Date.now() - res.locals.start +apiUtils.logTime = function(processLogger, res, str) { + processLogger.log('info', util.format( + 'completed %s in %sms', str, Date.now() - res.locals.start )); }; diff --git a/lib/api/internal.js b/lib/api/internal.js index 2bfb57e..0823b83 100644 --- a/lib/api/internal.js +++ b/lib/api/internal.js @@ -48,7 +48,7 @@ var rtResponse = function(env, req, res, data) { apiUtils.renderResponse(res, 'roundtrip', data); - apiUtils.logTime(env, res, 'parsing'); + env.log('info', 'completed in ' + (Date.now() - res.locals.start) + 'ms'); }; module.exports = function(parsoidConfig, processLogger) { diff --git a/lib/api/routes.js b/lib/api/routes.js index 260185f..78a9776 100644 --- a/lib/api/routes.js +++ b/lib/api/routes.js @@ -51,7 +51,7 @@ routes.v3Middle = function(req, res, next) { res.locals.titleMissing = !req.params.title; - res.locals.pageName = req.params.title || 'Main_Page'; + res.locals.pageName = req.params.title; res.locals.oldid = req.params.revision || null; // "body_only" flag to return just the body (instead of the entire HTML doc) @@ -198,7 +198,7 @@ // Validate and set the content version if (!apiUtils.validateAndSetContentVersion(res, acceptableTypes)) { - if (env.conf.parsoid.strictAcceptCheck) { + if (parsoidConfig.strictAcceptCheck) { var text = env.availableVersions.reduce(function(prev, curr) { return prev + apiUtils[opts.format + 'ContentType'](env, curr) + '\n'; }, 'Not acceptable.\n'); @@ -283,15 +283,9 @@ }); } - p = p.tap(function() { - env.bumpParserResourceUse('wikitextSize', - (typeof wt !== 'string' ? env.page.src : wt).length); - }); - var doSubst = (typeof wt === 'string' && res.locals.subst); if (doSubst) { p = p.then(function(wikitext) { - // FIXME: reset limits after subst'ing return apiUtils.substTopLevelTemplates(env, target, wikitext); }); } @@ -306,7 +300,7 @@ } // Follow redirects if asked - if (env.conf.parsoid.devAPI && req.query.follow_redirects) { + if (parsoidConfig.devAPI && req.query.follow_redirects) { // Get localized redirect matching regexp var reSrc = env.conf.wiki.getMagicWordMatcher('redirect').source; reSrc = '^[ \\t\\n\\r\\0\\x0b]*' + @@ -321,7 +315,7 @@ } } - env.log('info', 'started parsing'); + processLogger.log('info', 'started parsing'); var envOptions = Object.assign({ pageBundle: pageBundle, @@ -346,11 +340,6 @@ startTimers.get('wt2html.init')); startTimers.set('wt2html.wt.parse', Date.now()); metrics.timing('wt2html.wt.size.input', wikitext.length); - } - - if (!res.locals.pageName) { - // clear default page name - env.page.name = ''; } } else if (oldid)