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;
                if (useSelser) {
@@ -548,7 +541,7 @@
                                        startTimers.get('html2wt.total'));
                                metrics.timing('html2wt.size.output', 
out.wt.length);
                        }
-                       apiUtils.logTime(env, res, 'serializing');
+                       apiUtils.logTime(processLogger, res, 'serializing');
                        apiUtils.plainResponse(res, out.wt, undefined, 
apiUtils.wikitextContentType(env));
                });
        });
@@ -583,7 +576,7 @@
                        // Q(arlolra): Should redlinks be more complex than a 
bool?
                        // See gwicke's proposal at T114413#2240381
                        if (opts.updates && opts.updates.redlinks) {
-                               console.assert(env.conf.parsoid.useBatchAPI);
+                               console.assert(parsoidConfig.useBatchAPI);
                                // FIXME(arlolra): Maybe assert(revision === 
opts.original)
                                return apiUtils.updateRedLinks(env, revision, 
res, contentmodel);
                        } else {
diff --git a/lib/parse.js b/lib/parse.js
index 75f56ee..09cb425 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -165,7 +165,10 @@
                                        throw new Error('this is broken');
                                }
                        }
-                       return _html2wt(obj, env, obj.input, 
obj.pb).then(function(out) {
+                       var html = obj.input;
+                       env.bumpSerializerResourceUse('htmlSize', html.length);
+                       return _html2wt(obj, env, html, obj.pb)
+                       .then(function(out) {
                                return obj.mode === 'html2html' ? _wt2html(obj, 
env, out.wt) : out;
                        });
                } else { /* wt2html, wt2wt */
@@ -178,18 +181,21 @@
                                
env.cacheReusableExpansions(obj.reuseExpansions);
                        }
 
-                       if (obj.input === undefined) {
+                       var wt = obj.input;
+                       if (wt === undefined) {
                                var target = env.normalizeAndResolvePageTitle();
                                p = TemplateRequest
                                .setPageSrcInfo(env, target, obj.oldid)
                                .tap(function() {
                                        env.bumpTimeUse("Pre-parse (source 
fetch)", Date.now() - s1);
+                                       
env.bumpParserResourceUse('wikitextSize', env.page.src.length);
                                });
                        } else {
-                               p = Promise.resolve(obj.input);
+                               p = Promise.resolve();
+                               env.bumpParserResourceUse('wikitextSize', 
wt.length);
                        }
                        return p
-                       .then(function(wt) {
+                       .then(function() {
                                return _wt2html(obj, env, 
wt).then(function(out) {
                                        return obj.mode === 'wt2html' ? out : 
_html2wt(obj, env, out.html);
                                });

-- 
To view, visit https://gerrit.wikimedia.org/r/395583
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I55cb78bb09198cf419409c4802f8492adac25aea
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <abrea...@wikimedia.org>
Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org>
Gerrit-Reviewer: C. Scott Ananian <canan...@wikimedia.org>
Gerrit-Reviewer: Sbailey <sbai...@wikimedia.org>
Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to