From: Gilles Dubuc Date: Wed, 3 Apr 2019 07:06:38 +0000 (+0200) Subject: Make the ratio of requests getting Priority Hints configurable X-Git-Tag: 1.34.0-rc.0~1903 X-Git-Url: http://git.cyclocoop.org/%27.%28%24current%20%3E%202?a=commitdiff_plain;h=7433fa97f6ef1aa19114e111f3568c60080c262b;p=lhc%2Fweb%2Fwiklou.git Make the ratio of requests getting Priority Hints configurable This will allow to create 2 separate populations in order to verify the effect of the hint. It's fine if it's not exactly balanced in practice, what matters is getting a significant amount of traffic for both scenarios (origin trial is enabled + an image is given high prio/origin trial is enabled + no image is given special treatment). Bug: T216499 Change-Id: I373960b2bed8437c2e97e6d729d43aff6901046c --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index af830fde42..8b51c59bab 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -9024,6 +9024,16 @@ $wgOriginTrials = []; */ $wgPriorityHints = false; +/** + * Ratio of requests that should get Priority Hints when the feature is enabled. + * + * @warning EXPERIMENTAL! + * + * @since 1.34 + * @var float + */ +$wgPriorityHintsRatio = 1.0; + /** * Enable Element Timing. * diff --git a/includes/media/ThumbnailImage.php b/includes/media/ThumbnailImage.php index 36cf4228e5..7ee6dcbee3 100644 --- a/includes/media/ThumbnailImage.php +++ b/includes/media/ThumbnailImage.php @@ -110,7 +110,7 @@ class ThumbnailImage extends MediaTransformOutput { * @return string */ function toHtml( $options = [] ) { - global $wgPriorityHints, $wgElementTiming; + global $wgPriorityHints, $wgPriorityHintsRatio, $wgElementTiming; if ( func_num_args() == 2 ) { throw new MWException( __METHOD__ . ' called in the old style' ); @@ -133,8 +133,16 @@ class ThumbnailImage extends MediaTransformOutput { && $this->width * $this->height > 100 * 100 ) { self::$firstNonIconImageRendered = true; - $attribs['importance'] = 'high'; - $elementTimingName = 'thumbnail-high'; + // Generate a random number between 0.01 and 1.0, included + $random = rand( 1, 100 ) / 100.0; + + if ( $random <= $wgPriorityHintsRatio ) { + $attribs['importance'] = 'high'; + $elementTimingName = 'thumbnail-high'; + } else { + // This lets us track that the thumbnail *would* have gotten high priority but didn't. + $elementTimingName = 'thumbnail-top'; + } } if ( $wgElementTiming ) {