X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSiteStats.php;h=33bab6573f481c7a8d8fc9f275e2ba12448c56b9;hb=c30b04958083cfca0f20d63474f00d03a8c03112;hp=81172a14f7ac14b3543397e7c91ec1927ef02227;hpb=4e90d55fdc9d31d93e24cf05687eb7d180806f44;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SiteStats.php b/includes/SiteStats.php index 81172a14f7..33bab6573f 100644 --- a/includes/SiteStats.php +++ b/includes/SiteStats.php @@ -98,7 +98,7 @@ class SiteStats { } /** - * @param DatabaseBase $db + * @param IDatabase $db * @return bool|ResultWrapper */ static function doLoad( $db ) { @@ -180,23 +180,24 @@ class SiteStats { * @return int */ static function numberingroup( $group ) { - if ( !isset( self::$groupMemberCounts[$group] ) ) { - global $wgMemc; - $key = wfMemcKey( 'SiteStats', 'groupcounts', $group ); - $hit = $wgMemc->get( $key ); - if ( !$hit ) { + $cache = ObjectCache::getMainWANInstance(); + return $cache->getWithSetCallback( + wfMemcKey( 'SiteStats', 'groupcounts', $group ), + $cache::TTL_HOUR, + function ( $oldValue, &$ttl, array &$setOpts ) use ( $group ) { $dbr = wfGetDB( DB_SLAVE ); - $hit = $dbr->selectField( + + $setOpts += Database::getCacheSetOptions( $dbr ); + + return $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => $group ), __METHOD__ ); - $wgMemc->set( $key, $hit, 3600 ); - } - self::$groupMemberCounts[$group] = $hit; - } - return self::$groupMemberCounts[$group]; + }, + array( 'pcTTL' => 10 ) + ); } /** @@ -281,12 +282,12 @@ class SiteStatsInit { /** * Constructor - * @param bool|DatabaseBase $database - * - Boolean: whether to use the master DB - * - DatabaseBase: database connection to use + * @param bool|IDatabase $database + * - boolean: Whether to use the master DB + * - IDatabase: Database connection to use */ public function __construct( $database = false ) { - if ( $database instanceof DatabaseBase ) { + if ( $database instanceof IDatabase ) { $this->db = $database; } else { $this->db = wfGetDB( $database ? DB_MASTER : DB_SLAVE ); @@ -364,11 +365,11 @@ class SiteStatsInit { * Do all updates and commit them. More or less a replacement * for the original initStats, but without output. * - * @param DatabaseBase|bool $database - * - Boolean: whether to use the master DB - * - DatabaseBase: database connection to use + * @param IDatabase|bool $database + * - boolean: 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 boolean: Whether to update the number of active users (default: false) */ public static function doAllAndCommit( $database, array $options = array() ) { $options += array( 'update' => false, 'activeUsers' => false );