From 8309d7ea8856ab76a88b864100b70b0612321e60 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Wed, 21 Jan 2015 01:56:45 +0100 Subject: [PATCH] Collect thumbnail width in the performance log Bug: T86609 Change-Id: Ia0934cf76c323b9bcb2ee7b0ee8ee6ca2aefc600 --- MultimediaViewer.php | 2 +- resources/mmv/mmv.js | 6 ++++++ tests/qunit/mmv/mmv.test.js | 16 ++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/MultimediaViewer.php b/MultimediaViewer.php index d2eb90329..2371ba48c 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -1070,7 +1070,7 @@ $wgResourceModules += array( $wgHooks['EventLoggingRegisterSchemas'][] = function( array &$schemas ) { $schemas += array( 'MediaViewer' => 10867062, - 'MultimediaViewerNetworkPerformance' => 10774577, + 'MultimediaViewerNetworkPerformance' => 11030254, 'MultimediaViewerDuration' => 10427980, 'MultimediaViewerAttribution' => 9758179, 'MultimediaViewerDimensions' => 10014238, diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js index 6368a95ac..2fa75cca5 100644 --- a/resources/mmv/mmv.js +++ b/resources/mmv/mmv.js @@ -787,6 +787,12 @@ thumbnailPromise = this.thumbnailInfoProvider.get( fileTitle, width ); } + // Add thumbnail width to the extra stats passed to the performance log + extraStatsDeferred = $.when( extraStatsDeferred || {} ).then( function ( extraStats ) { + extraStats.imageWidth = width; + return extraStats; + } ); + imagePromise = thumbnailPromise.then( function ( thumbnail ) { return viewer.imageProvider.get( thumbnail.url, extraStatsDeferred ); } ); diff --git a/tests/qunit/mmv/mmv.test.js b/tests/qunit/mmv/mmv.test.js index 1d1951a5a..e0136d1e7 100644 --- a/tests/qunit/mmv/mmv.test.js +++ b/tests/qunit/mmv/mmv.test.js @@ -557,7 +557,7 @@ assert.ok( !guessedThumbnailInfoStub.called, 'When we lack sample URL and original dimensions, GuessedThumbnailInfoProvider is not called' ); assert.ok( thumbnailInfoStub.calledOnce, 'When we lack sample URL and original dimensions, ThumbnailInfoProvider is called once' ); assert.ok( imageStub.calledOnce, 'When we lack sample URL and original dimensions, ImageProvider is called once' ); - assert.ok( imageStub.calledWithExactly( 'apiURL', undefined ), 'When we lack sample URL and original dimensions, ImageProvider is called with the API url' ); + assert.ok( imageStub.calledWith( 'apiURL' ), 'When we lack sample URL and original dimensions, ImageProvider is called with the API url' ); assert.strictEqual( promise.state(), 'resolved', 'When we lack sample URL and original dimensions, fetchThumbnail resolves' ); // When the guesser bails out, the classic provider should be used @@ -569,7 +569,7 @@ assert.ok( guessedThumbnailInfoStub.calledOnce, 'When the guesser bails out, GuessedThumbnailInfoProvider is called once' ); assert.ok( thumbnailInfoStub.calledOnce, 'When the guesser bails out, ThumbnailInfoProvider is called once' ); assert.ok( imageStub.calledOnce, 'When the guesser bails out, ImageProvider is called once' ); - assert.ok( imageStub.calledWithExactly( 'apiURL', undefined ), 'When the guesser bails out, ImageProvider is called with the API url' ); + assert.ok( imageStub.calledWith( 'apiURL' ), 'When the guesser bails out, ImageProvider is called with the API url' ); assert.strictEqual( promise.state(), 'resolved', 'When the guesser bails out, fetchThumbnail resolves' ); // When the guesser returns an URL, that should be used @@ -581,7 +581,7 @@ assert.ok( guessedThumbnailInfoStub.calledOnce, 'When the guesser returns an URL, GuessedThumbnailInfoProvider is called once' ); assert.ok( !thumbnailInfoStub.called, 'When the guesser returns an URL, ThumbnailInfoProvider is not called' ); assert.ok( imageStub.calledOnce, 'When the guesser returns an URL, ImageProvider is called once' ); - assert.ok( imageStub.calledWithExactly( 'guessedURL', undefined ), 'When the guesser returns an URL, ImageProvider is called with the guessed url' ); + assert.ok( imageStub.calledWith( 'guessedURL' ), 'When the guesser returns an URL, ImageProvider is called with the guessed url' ); assert.strictEqual( promise.state(), 'resolved', 'When the guesser returns an URL, fetchThumbnail resolves' ); // When the guesser returns an URL, but that returns 404, image loading should be retried with the classic provider @@ -594,8 +594,8 @@ assert.ok( guessedThumbnailInfoStub.calledOnce, 'When the guesser returns an URL, but that returns 404, GuessedThumbnailInfoProvider is called once' ); assert.ok( thumbnailInfoStub.calledOnce, 'When the guesser returns an URL, but that returns 404, ThumbnailInfoProvider is called once' ); assert.ok( imageStub.calledTwice, 'When the guesser returns an URL, but that returns 404, ImageProvider is called twice' ); - assert.ok( imageStub.getCall( 0 ).calledWithExactly( 'guessedURL', undefined ), 'When the guesser returns an URL, but that returns 404, ImageProvider is called first with the guessed url' ); - assert.ok( imageStub.getCall( 1 ).calledWithExactly( 'apiURL', undefined ), 'When the guesser returns an URL, but that returns 404, ImageProvider is called second with the guessed url' ); + assert.ok( imageStub.getCall( 0 ).calledWith( 'guessedURL' ), 'When the guesser returns an URL, but that returns 404, ImageProvider is called first with the guessed url' ); + assert.ok( imageStub.getCall( 1 ).calledWith( 'apiURL' ), 'When the guesser returns an URL, but that returns 404, ImageProvider is called second with the guessed url' ); assert.strictEqual( promise.state(), 'resolved', 'When the guesser returns an URL, but that returns 404, fetchThumbnail resolves' ); // When even the retry fails, fetchThumbnail() should reject @@ -608,8 +608,8 @@ assert.ok( guessedThumbnailInfoStub.calledOnce, 'When even the retry fails, GuessedThumbnailInfoProvider is called once' ); assert.ok( thumbnailInfoStub.calledOnce, 'When even the retry fails, ThumbnailInfoProvider is called once' ); assert.ok( imageStub.calledTwice, 'When even the retry fails, ImageProvider is called twice' ); - assert.ok( imageStub.getCall( 0 ).calledWithExactly( 'guessedURL', undefined ), 'When even the retry fails, ImageProvider is called first with the guessed url' ); - assert.ok( imageStub.getCall( 1 ).calledWithExactly( 'apiURL', undefined ), 'When even the retry fails, ImageProvider is called second with the guessed url' ); + assert.ok( imageStub.getCall( 0 ).calledWith( 'guessedURL' ), 'When even the retry fails, ImageProvider is called first with the guessed url' ); + assert.ok( imageStub.getCall( 1 ).calledWith( 'apiURL' ), 'When even the retry fails, ImageProvider is called second with the guessed url' ); assert.strictEqual( promise.state(), 'rejected', 'When even the retry fails, fetchThumbnail rejects' ); mw.config.get( 'wgMultimediaViewer' ).useThumbnailGuessing = false; @@ -623,7 +623,7 @@ assert.ok( !guessedThumbnailInfoStub.called, 'When guessing is disabled, GuessedThumbnailInfoProvider is not called' ); assert.ok( thumbnailInfoStub.calledOnce, 'When guessing is disabled, ThumbnailInfoProvider is called once' ); assert.ok( imageStub.calledOnce, 'When guessing is disabled, ImageProvider is called once' ); - assert.ok( imageStub.calledWithExactly( 'apiURL', undefined ), 'When guessing is disabled, ImageProvider is called with the API url' ); + assert.ok( imageStub.calledWith( 'apiURL' ), 'When guessing is disabled, ImageProvider is called with the API url' ); assert.strictEqual( promise.state(), 'resolved', 'When guessing is disabled, fetchThumbnail resolves' ); mw.config.get( 'wgMultimediaViewer' ).useThumbnailGuessing = oldUseThumbnailGuessing;