From 0e782adf7d4f0d64cc81284702493f575e78dc36 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Thu, 6 Nov 2014 18:51:08 +0100 Subject: [PATCH] Add the ability to apply a different duration sampling factor to loggedin users Change-Id: I10fc042ddf50f02e1a86711621b66c14fc981311 Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/978 --- MultimediaViewer.php | 10 ++++++++++ MultimediaViewerHooks.php | 6 ++++-- resources/mmv/logging/mmv.logging.DurationLogger.js | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/MultimediaViewer.php b/MultimediaViewer.php index 5822e442b..9aa2ae937 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -35,6 +35,16 @@ if ( !isset( $wgMediaViewerDurationLoggingSamplingFactor ) ) { $wgMediaViewerDurationLoggingSamplingFactor = false; } +if ( !isset( $wgMediaViewerDurationLoggingLoggedinSamplingFactor ) ) { + /** + * If set, records loading times via EventLogging with factor specific to loggedin users. + * A value of 1000 means there will be an 1:1000 chance to log the duration event. + * False if unset. + * @var int|bool + */ + $wgMediaViewerDurationLoggingLoggedinSamplingFactor = false; +} + if ( !isset( $wgMediaViewerAttributionLoggingSamplingFactor ) ) { /** * If set, records whether image attribution data was available. A value of 1000 means there will be an diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php index 53c17d18b..bf6d36fb8 100644 --- a/MultimediaViewerHooks.php +++ b/MultimediaViewerHooks.php @@ -140,14 +140,16 @@ class MultimediaViewerHooks { */ public static function resourceLoaderGetConfigVars( &$vars ) { global $wgMediaViewerActionLoggingSamplingFactorMap, $wgNetworkPerformanceSamplingFactor, - $wgMediaViewerDurationLoggingSamplingFactor, $wgMediaViewerAttributionLoggingSamplingFactor, - $wgMediaViewerDimensionLoggingSamplingFactor, $wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing; + $wgMediaViewerDurationLoggingSamplingFactor, $wgMediaViewerDurationLoggingLoggedinSamplingFactor, + $wgMediaViewerAttributionLoggingSamplingFactor, $wgMediaViewerDimensionLoggingSamplingFactor, + $wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing; $vars['wgMultimediaViewer'] = array( 'infoLink' => self::$infoLink, 'discussionLink' => self::$discussionLink, 'helpLink' => self::$helpLink, 'useThumbnailGuessing' => (bool)$wgMediaViewerUseThumbnailGuessing, 'durationSamplingFactor' => $wgMediaViewerDurationLoggingSamplingFactor, + 'durationSamplingFactorLoggedin' => $wgMediaViewerDurationLoggingLoggedinSamplingFactor, 'networkPerformanceSamplingFactor' => $wgNetworkPerformanceSamplingFactor, 'actionLoggingSamplingFactorMap' => $wgMediaViewerActionLoggingSamplingFactorMap, 'attributionSamplingFactor' => $wgMediaViewerAttributionLoggingSamplingFactor, diff --git a/resources/mmv/logging/mmv.logging.DurationLogger.js b/resources/mmv/logging/mmv.logging.DurationLogger.js index 1a769d7b2..46e85557f 100644 --- a/resources/mmv/logging/mmv.logging.DurationLogger.js +++ b/resources/mmv/logging/mmv.logging.DurationLogger.js @@ -38,6 +38,11 @@ */ L.samplingFactor = mw.config.get( 'wgMultimediaViewer' ).durationSamplingFactor; + // If a sampling factor specific to loggedin users is set and we're logged in, apply it + if ( mw.config.get( 'wgMultimediaViewer' ).durationSamplingFactorLoggedin && !mw.user.isAnon() ) { + L.samplingFactor = mw.config.get( 'wgMultimediaViewer' ).durationSamplingFactorLoggedin; + } + /** * @override * @inheritdoc