Don't bother fetching metadata for diffs

Only HTML content is used for building diffs

Change-Id: I4f9af162792c27e7771838b6294c106bc9dc359a
This commit is contained in:
Ed Sanders 2019-12-02 17:20:09 +00:00
parent f213e370f7
commit e6bb954edd
2 changed files with 32 additions and 18 deletions

View file

@ -197,9 +197,11 @@
* @param {string} pageName See #requestPageData
* @param {Object} [options] See #requestPageData
* @param {boolean} [noRestbase=false] Don't query RESTBase directly
* @param {boolean} [noMetadata=false] Don't fetch document metadata when querying RESTBase. Metadata
* is not required for some use cases, e.g. diffing.
* @return {jQuery.Promise} Abortable promise resolved with a JSON object
*/
requestParsoidData: function ( pageName, options, noRestbase ) {
requestParsoidData: function ( pageName, options, noRestbase, noMetadata ) {
var start, apiXhr, restbaseXhr, apiPromise, restbasePromise, dataPromise, pageHtmlUrl, headers, data, abort,
section = options.section !== undefined ? options.section : null,
useRestbase = !noRestbase && ( conf.fullRestbaseUrl || conf.restbaseUrl ) && section === null,
@ -241,23 +243,29 @@
data.oldid = options.oldId;
apiXhr = new mw.Api().post( data );
} else {
apiXhr = new mw.Api().get( data );
}
apiPromise = apiXhr.then( function ( data, jqxhr ) {
ve.track( 'trace.apiLoad.exit', { mode: 'visual' } );
ve.track( 'mwtiming.performance.system.apiLoad', {
bytes: require( 'mediawiki.String' ).byteLength( jqxhr.responseText ),
duration: ve.now() - start,
cacheHit: /hit/i.test( jqxhr.getResponseHeader( 'X-Cache' ) ),
targetName: options.targetName,
mode: 'visual'
} );
if ( data.visualeditor ) {
data.visualeditor.switched = switched;
data.visualeditor.fromEditedState = fromEditedState;
if ( noMetadata ) {
apiPromise = $.Deferred().resolve( { visualeditor: {} } ).promise();
} else {
apiXhr = new mw.Api().get( data );
}
return data;
} );
}
if ( !apiPromise ) {
apiPromise = apiXhr.then( function ( data, jqxhr ) {
ve.track( 'trace.apiLoad.exit', { mode: 'visual' } );
ve.track( 'mwtiming.performance.system.apiLoad', {
bytes: require( 'mediawiki.String' ).byteLength( jqxhr.responseText ),
duration: ve.now() - start,
cacheHit: /hit/i.test( jqxhr.getResponseHeader( 'X-Cache' ) ),
targetName: options.targetName,
mode: 'visual'
} );
if ( data.visualeditor ) {
data.visualeditor.switched = switched;
data.visualeditor.fromEditedState = fromEditedState;
}
return data;
} );
}
if ( useRestbase ) {
ve.track( 'trace.restbaseLoad.enter', { mode: 'visual' } );

View file

@ -65,7 +65,13 @@
cacheKey = revId + ( section !== null ? '/' + section : '' );
revCache[ cacheKey ] = revCache[ cacheKey ] ||
mw.libs.ve.targetLoader.requestParsoidData( pageName, { oldId: revId, targetName: 'diff' } ).then( function ( response ) {
mw.libs.ve.targetLoader.requestParsoidData(
pageName,
{ oldId: revId, targetName: 'diff' },
false,
// noMetadata, we only use `content` in getModelFromResponse
true
).then( function ( response ) {
return parseDocumentModulePromise.then( function () {
return mw.libs.ve.diffLoader.getModelFromResponse( response, section );
} );