mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-27 04:06:51 +00:00
9b582485f9
* Use the event's timeStamp rather than the current time in the event subscriber. * Instead of using ve.trackSubscribeAll() and then branching on the topic prefix, just use ve.trackSubscribe( prefix, ... ) to bind prefix-specific handlers. * Round timing measurements after performing arithmetic, and use Math#round rather than Math#floor. * Rename 'getDefaultTiming' to 'computeDuration'. Change-Id: I27ff1622ecea9b82d414f871441f127fc2dbd2cc
114 lines
3.3 KiB
JavaScript
114 lines
3.3 KiB
JavaScript
/*!
|
|
* VisualEditor MediaWiki event subscriber.
|
|
*
|
|
* Subscribes to ve.track() events and routes them to mw.track().
|
|
*
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
( function () {
|
|
|
|
var timing = {},
|
|
editingSessionId = mw.user.generateRandomSessionId();
|
|
|
|
function computeDuration( action, event, timeStamp ) {
|
|
if ( event.timing !== undefined ) {
|
|
return event.timing;
|
|
}
|
|
|
|
switch ( action ) {
|
|
case 'init':
|
|
// Account for second opening
|
|
return timeStamp - Math.max(
|
|
window.mediaWikiLoadStart,
|
|
timing.saveSuccess || 0,
|
|
timing.abort || 0
|
|
);
|
|
case 'ready':
|
|
return timeStamp - timing.init;
|
|
case 'saveIntent':
|
|
return timeStamp - timing.ready;
|
|
case 'saveAttempt':
|
|
return timeStamp - timing.saveIntent;
|
|
case 'saveSuccess':
|
|
case 'saveFailure':
|
|
// HERE BE DRAGONS: the caller must compute these themselves
|
|
// for sensible results. Deliberately sabotage any attempts to
|
|
// use the default by returning -1
|
|
mw.log.warn( 've.init.mw.trackSubscriber: Do not rely on default timing value for saveSuccess/saveFailure' );
|
|
return -1;
|
|
case 'abort':
|
|
switch ( event.type ) {
|
|
case 'preinit':
|
|
return timeStamp - timing.init;
|
|
case 'nochange':
|
|
case 'switchwith':
|
|
case 'switchwithout':
|
|
case 'abandon':
|
|
return timeStamp - timing.ready;
|
|
case 'abandonMidsave':
|
|
return timeStamp - timing.saveAttempt;
|
|
}
|
|
}
|
|
mw.log.warn( 've.init.mw.trackSubscriber: Unrecognized action', action );
|
|
return -1;
|
|
}
|
|
|
|
ve.trackSubscribe( 'mwedit.', function ( topic, data, timeStamp ) {
|
|
var action = topic.split( '.' )[1],
|
|
event;
|
|
|
|
timing[action] = timeStamp || this.timeStamp; // I8e82acc12 back-compat
|
|
|
|
if ( action === 'init' ) {
|
|
// Regenerate editingSessionId
|
|
editingSessionId = mw.user.generateRandomSessionId();
|
|
}
|
|
|
|
event = $.extend( {
|
|
version: 1,
|
|
action: action,
|
|
editor: 'visualeditor',
|
|
platform: 'desktop', // FIXME
|
|
integration: ve.init && ve.init.target && ve.init.target.constructor.static.integrationType || 'page',
|
|
'page.id': mw.config.get( 'wgArticleId' ),
|
|
'page.title': mw.config.get( 'wgPageName' ),
|
|
'page.ns': mw.config.get( 'wgNamespaceNumber' ),
|
|
'page.revid': mw.config.get( 'wgRevisionId' ),
|
|
'page.length': -1, // FIXME
|
|
editingSessionId: editingSessionId,
|
|
'user.id': mw.user.getId(),
|
|
'user.editCount': mw.config.get( 'wgUserEditCount', 0 ),
|
|
'mediawiki.version': mw.config.get( 'wgVersion' )
|
|
}, data );
|
|
|
|
if ( mw.user.isAnon() ) {
|
|
event['user.class'] = 'IP';
|
|
}
|
|
|
|
event['action.' + action + '.type'] = event.type;
|
|
event['action.' + action + '.mechanism'] = event.mechanism;
|
|
event['action.' + action + '.timing'] = Math.round( computeDuration( action, event, this.timeStamp ) );
|
|
|
|
// Remove renamed properties
|
|
delete event.type;
|
|
delete event.mechanism;
|
|
delete event.timing;
|
|
|
|
mw.track( 'event.Edit', event );
|
|
} );
|
|
|
|
ve.trackSubscribe( 'mwtiming.', function ( topic, data ) {
|
|
// Add type for save errors; not in the topic for stupid historical reasons
|
|
if ( topic === 'mwtiming.performance.user.saveError' ) {
|
|
topic = topic + '.' + data.type;
|
|
}
|
|
|
|
// Map mwtiming.foo --> timing.ve.foo.mobile
|
|
topic = topic.replace( /^mwtiming/, 'timing.ve.' + data.targetName );
|
|
mw.track( topic, data.duration );
|
|
} );
|
|
|
|
} )();
|