Gilles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/171228

Change subject: [WIP] Track the most recent upload time for duration events
......................................................................

[WIP] Track the most recent upload time for duration events

This will allow us to see if images uploaded recently, which have been
subjected to thumbnail prerendering, load faster.

I still need to take care of the QUnit tests.

Change-Id: I4ce358ff54e4ca4e290349aa3ff4810ad4714d24
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/975
---
M MultimediaViewer.php
M resources/mmv/logging/mmv.logging.DurationLogger.js
M resources/mmv/mmv.head.js
M resources/mmv/mmv.js
4 files changed, 72 insertions(+), 28 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer 
refs/changes/28/171228/1

diff --git a/MultimediaViewer.php b/MultimediaViewer.php
index 5822e44..5e3434c 100644
--- a/MultimediaViewer.php
+++ b/MultimediaViewer.php
@@ -1015,7 +1015,7 @@
        $schemas += array(
                'MediaViewer' => 10308479,
                'MultimediaViewerNetworkPerformance' => 7917896,
-               'MultimediaViewerDuration' => 8572641,
+               'MultimediaViewerDuration' => 10427980,
                'MultimediaViewerAttribution' => 9758179,
                'MultimediaViewerDimensions' => 10014238,
        );
diff --git a/resources/mmv/logging/mmv.logging.DurationLogger.js 
b/resources/mmv/logging/mmv.logging.DurationLogger.js
index 1a769d7..ed13b45 100644
--- a/resources/mmv/logging/mmv.logging.DurationLogger.js
+++ b/resources/mmv/logging/mmv.logging.DurationLogger.js
@@ -26,6 +26,7 @@
         */
        function DurationLogger() {
                this.starts = {};
+               this.stops = {};
        }
 
        oo.inheritClass( DurationLogger, mw.mmv.logging.Logger );
@@ -66,43 +67,79 @@
                                this.starts[ typeOrTypes[ i ] ] = start;
                        }
                }
+
+               return this;
        };
 
        /**
-        * Logs a duration if a start was recorded first
+        * Saves the stop of a duration
         * @param {string} type Type of duration being measured.
-        * @param {number} start Start timestamp that to substitute the one 
coming from start()
+        * @param {number} start Start timestamp to substitute the one coming 
from start()
         */
        L.stop = function ( type, start ) {
-               var e, duration, message, startTimestamp;
+               var stop = $.now();
 
                if ( !type ) {
                        throw 'Must specify type';
                }
 
-               startTimestamp = this.starts.hasOwnProperty( type ) ? 
this.starts[ type ] : start;
-
-               if ( startTimestamp !== undefined ) {
-                       duration = $.now() - startTimestamp;
-
-                       e = {
-                               type : type,
-                               duration : duration,
-                               loggedIn : !mw.user.isAnon(),
-                               samplingFactor : this.samplingFactor
-                       };
-
-                       message = type + ': ' + duration + 'ms';
-
-                       mw.log( message );
-
-                       this.log( e );
+               // Don't overwrite an existing value
+               if ( !this.stops.hasOwnProperty( type ) ) {
+                       this.stops[ type ] = stop;
                }
 
-               if ( this.starts.hasOwnProperty( type ) ) {
-                       delete this.starts[ type ];
+               // May overwrite an existint value
+               if ( start ) {
+                       this.starts[ type ] = start;
                }
+
+               return this;
        };
 
+       /**
+        * Records the duration log event
+        * @param {string} type Type of duration being measured.
+        * @param {Object} extraData Extra information to add to the log event 
data
+        */
+       L.record = function ( type, extraData ) {
+               var e, message, duration;
+
+               if ( !type ) {
+                       throw 'Must specify type';
+               }
+
+               if ( !this.starts.hasOwnProperty( type ) || this.starts[ type ] 
=== undefined ) {
+                       return;
+               }
+
+               if ( !this.stops.hasOwnProperty( type ) || this.stops[ type ] 
=== undefined ) {
+                       return;
+               }
+
+               duration = this.stops[ type ] - this.starts[ type ];
+
+               e = {
+                       type : type,
+                       duration : duration,
+                       loggedIn : !mw.user.isAnon(),
+                       samplingFactor : this.samplingFactor
+               };
+
+               if ( extraData ) {
+                       $.each( extraData, function ( key, value ) {
+                               e[ key ] = value;
+                       } );
+               }
+
+               mw.log( 'mw.mmw.logger.DurationLogger', e );
+
+               this.log( e );
+
+               delete this.starts[ type ];
+               delete this.stops[ type ];
+
+               return this;
+       }
+
        mw.mmv.durationLogger = new DurationLogger();
 }( mediaWiki, jQuery, OO ) );
\ No newline at end of file
diff --git a/resources/mmv/mmv.head.js b/resources/mmv/mmv.head.js
index 43a8b63..0310c51 100644
--- a/resources/mmv/mmv.head.js
+++ b/resources/mmv/mmv.head.js
@@ -46,7 +46,7 @@
                $document.ready( function () {
                        mw.loader.using( [ 'mmv.bootstrap.autostart', 
'mmv.logging.DurationLogger' ] , function() {
                                mw.mmv.bootstrap.whenThumbsReady().then( 
function () {
-                                       mw.mmv.durationLogger.stop( 
'early-click-to-replay-click', start );
+                                       mw.mmv.durationLogger.stop( 
'early-click-to-replay-click', start ).record( 'early-click-to-replay-click' );
 
                                        // We have to copy the properties, 
passing e doesn't work. Probably because of preventDefault()
                                        $( e.target ).trigger( { type : 
'click', which: 1, replayed: true } );
diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js
index 46d440c..a175258 100644
--- a/resources/mmv/mmv.js
+++ b/resources/mmv/mmv.js
@@ -278,6 +278,8 @@
 
                this.setupProgressBar( image, imagePromise, imageWidths.real );
 
+               metadataPromise = this.fetchSizeIndependentLightboxInfo( 
image.filePageTitle );
+
                imagePromise.done( function ( thumbnail, imageElement ) {
                        if ( viewer.currentIndex !== image.index ) {
                                return;
@@ -285,22 +287,27 @@
 
                        if ( viewer.imageDisplayedCount++ === 0 ) {
                                mw.mmv.durationLogger.stop( 
'click-to-first-image' );
+
+                               metadataPromise.done( function ( imageInfo, 
repoInfo, userInfo ) {
+                                       mw.mmv.durationLogger.record( 
'click-to-first-image', {
+                                               uploadTimestamp: 
imageInfo.uploadDateTime.toString().replace( /[:\s]/g, '' )
+                                       } );
+                               } );
                        }
                        viewer.displayRealThumbnail( thumbnail, imageElement, 
imageWidths, $.now() - start );
                } ).fail( function ( error ) {
                        viewer.ui.canvas.showError( error );
                } );
 
-               metadataPromise = this.fetchSizeIndependentLightboxInfo(
-                       image.filePageTitle
-               ).done( function ( imageInfo, repoInfo, userInfo ) {
+               metadataPromise.done( function ( imageInfo, repoInfo, userInfo 
) {
                        if ( viewer.currentIndex !== image.index ) {
                                return;
                        }
 
                        if ( viewer.metadataDisplayedCount++ === 0 ) {
-                               mw.mmv.durationLogger.stop( 
'click-to-first-metadata' );
+                               mw.mmv.durationLogger.stop( 
'click-to-first-metadata' ).record( 'click-to-first-metadata' );
                        }
+
                        viewer.ui.panel.setImageInfo( image, imageInfo, 
repoInfo, userInfo );
 
                        // File reuse steals a bunch of information from the 
DOM, so do it last

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4ce358ff54e4ca4e290349aa3ff4810ad4714d24
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: Gilles <gdu...@wikimedia.org>

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

Reply via email to