X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSiteStats.php;h=ce87596a5fbd298386b9a89bc0d66ac0b0e16073;hb=8f4ae0d51c8b4c4f77753e157312a91176f5a719;hp=5a0947d0e7cdfc4d46e6bf093a84560b64d3725d;hpb=a8dcb178c7e347ef56bef1e36bb4a26a61a1d82b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SiteStats.php b/includes/SiteStats.php index 5a0947d0e7..ce87596a5f 100644 --- a/includes/SiteStats.php +++ b/includes/SiteStats.php @@ -34,9 +34,6 @@ class SiteStats { /** @var bool */ private static $loaded = false; - /** @var int */ - private static $jobs; - /** @var int[] */ private static $pageCount = []; @@ -213,24 +210,24 @@ class SiteStats { } /** + * Total number of jobs in the job queue. * @return int */ static function jobs() { - if ( !isset( self::$jobs ) ) { - try{ - self::$jobs = array_sum( JobQueueGroup::singleton()->getQueueSizes() ); - } catch ( JobQueueError $e ) { - self::$jobs = 0; - } - /** - * Zero rows still do single row read for row that doesn't exist, - * but people are annoyed by that - */ - if ( self::$jobs == 1 ) { - self::$jobs = 0; - } - } - return self::$jobs; + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + return $cache->getWithSetCallback( + $cache->makeKey( 'SiteStats', 'jobscount' ), + $cache::TTL_MINUTE, + function ( $oldValue, &$ttl, array &$setOpts ) { + try{ + $jobs = array_sum( JobQueueGroup::singleton()->getQueueSizes() ); + } catch ( JobQueueError $e ) { + $jobs = 0; + } + return $jobs; + }, + [ 'pcTTL' => $cache::TTL_PROC_LONG ] + ); } /** @@ -297,7 +294,7 @@ class SiteStatsInit { /** * @param bool|IDatabase $database - * - boolean: Whether to use the master DB + * - bool: Whether to use the master DB * - IDatabase: Database connection to use */ public function __construct( $database = false ) { @@ -382,10 +379,10 @@ class SiteStatsInit { * for the original initStats, but without output. * * @param IDatabase|bool $database - * - boolean: Whether to use the master DB + * - bool: Whether to use the master DB * - IDatabase: Database connection to use * @param array $options Array of options, may contain the following values - * - activeUsers boolean: Whether to update the number of active users (default: false) + * - activeUsers bool: Whether to update the number of active users (default: false) */ public static function doAllAndCommit( $database, array $options = [] ) { $options += [ 'update' => false, 'activeUsers' => false ];