X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fparser%2FParserOutput.php;h=d2ef5e303918e1593f577c3d52d1cee50ff47ccc;hp=3462d10c7dd9c4651107e286200cc2629c684010;hb=0e15a6068a5a07fc109b5898ae51fdb8decafaf0;hpb=b3307c8a5a6b1ea0820b91687f83aaf23f8cd29f diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 3462d10c7d..d2ef5e3039 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -211,9 +211,21 @@ class ParserOutput extends CacheTime { /** @var integer|null Assumed rev ID for {{REVISIONID}} if no revision is set */ private $mSpeculativeRevId; + /** @var integer Upper bound of expiry based on parse duration */ + private $mMaxAdaptiveExpiry = INF; + const EDITSECTION_REGEX = '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)())#'; + // finalizeAdaptiveCacheExpiry() uses TTL = MAX( m * PARSE_TIME + b, MIN_AR_TTL) + // Current values imply that m=3933.333333 and b=-333.333333 + // See https://www.nngroup.com/articles/website-response-times/ + const PARSE_FAST_SEC = .100; // perceived "fast" page parse + const PARSE_SLOW_SEC = 1.0; // perceived "slow" page parse + const FAST_AR_TTL = 60; // adaptive TTL for "fast" pages + const SLOW_AR_TTL = 3600; // adaptive TTL for "slow" pages + const MIN_AR_TTL = 15; // min adaptive TTL (for sanity, pool counter, and edit stashing) + public function __construct( $text = '', $languageLinks = [], $categoryLinks = [], $unused = false, $titletext = '' ) { @@ -367,15 +379,6 @@ class ParserOutput extends CacheTime { return $this->mModuleStyles; } - /** - * @deprecated since 1.26 Obsolete - * @return array - */ - public function getModuleMessages() { - wfDeprecated( __METHOD__, '1.26' ); - return []; - } - /** @since 1.23 */ public function getJsConfigVars() { return $this->mJsConfigVars; @@ -644,14 +647,6 @@ class ParserOutput extends CacheTime { $this->mModuleStyles = array_merge( $this->mModuleStyles, (array)$modules ); } - /** - * @deprecated since 1.26 Use addModules() instead - * @param string|array $modules - */ - public function addModuleMessages( $modules ) { - wfDeprecated( __METHOD__, '1.26' ); - } - /** * Add one or more variables to be set in mw.config in JavaScript. * @@ -1046,9 +1041,41 @@ class ParserOutput extends CacheTime { } /** - * Save space for serialization by removing useless values - * @return array + * Lower the runtime adaptive TTL to at most this value + * + * @param integer $ttl + * @since 1.28 */ + public function updateRuntimeAdaptiveExpiry( $ttl ) { + $this->mMaxAdaptiveExpiry = min( $ttl, $this->mMaxAdaptiveExpiry ); + $this->updateCacheExpiry( $ttl ); + } + + /** + * Call this when parsing is done to lower the TTL based on low parse times + * + * @since 1.28 + */ + public function finalizeAdaptiveCacheExpiry() { + if ( is_infinite( $this->mMaxAdaptiveExpiry ) ) { + return; // not set + } + + $runtime = $this->getTimeSinceStart( 'wall' ); + if ( is_float( $runtime ) ) { + $slope = ( self::SLOW_AR_TTL - self::FAST_AR_TTL ) + / ( self::PARSE_SLOW_SEC - self::PARSE_FAST_SEC ); + // SLOW_AR_TTL = PARSE_SLOW_SEC * $slope + $point + $point = self::SLOW_AR_TTL - self::PARSE_SLOW_SEC * $slope; + + $adaptiveTTL = min( + max( $slope * $runtime + $point, self::MIN_AR_TTL ), + $this->mMaxAdaptiveExpiry + ); + $this->updateCacheExpiry( $adaptiveTTL ); + } + } + public function __sleep() { return array_diff( array_keys( get_object_vars( $this ) ),