Merge "Add 3D filetype for STL files"
[lhc/web/wiklou.git] / includes / SiteStats.php
index bc6b842..6ce1aed 100644 (file)
@@ -20,7 +20,9 @@
  * @file
  */
 
+use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\MediaWikiServices;
 
 /**
  * Static accessor class for site_stats and related things
@@ -77,9 +79,12 @@ class SiteStats {
                $row = self::doLoad( wfGetDB( DB_REPLICA ) );
 
                if ( !self::isSane( $row ) ) {
-                       // Might have just been initialized during this request? Underflow?
-                       wfDebug( __METHOD__ . ": site_stats damaged or missing on replica DB\n" );
-                       $row = self::doLoad( wfGetDB( DB_MASTER ) );
+                       $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
+                       if ( $lb->hasOrMadeRecentMasterChanges() ) {
+                               // Might have just been initialized during this request? Underflow?
+                               wfDebug( __METHOD__ . ": site_stats damaged or missing on replica DB\n" );
+                               $row = self::doLoad( wfGetDB( DB_MASTER ) );
+                       }
                }
 
                if ( !$wgMiserMode && !self::isSane( $row ) ) {
@@ -97,6 +102,7 @@ class SiteStats {
                if ( !self::isSane( $row ) ) {
                        wfDebug( __METHOD__ . ": site_stats persistently nonsensical o_O\n" );
                }
+
                return $row;
        }
 
@@ -183,12 +189,11 @@ class SiteStats {
         * @return int
         */
        static function numberingroup( $group ) {
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                return $cache->getWithSetCallback(
-                       wfMemcKey( 'SiteStats', 'groupcounts', $group ),
+                       $cache->makeKey( 'SiteStats', 'groupcounts', $group ),
                        $cache::TTL_HOUR,
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $group ) {
-                               global $wgDisableUserGroupExpiry;
                                $dbr = wfGetDB( DB_REPLICA );
 
                                $setOpts += Database::getCacheSetOptions( $dbr );
@@ -198,9 +203,7 @@ class SiteStats {
                                        'COUNT(*)',
                                        [
                                                'ug_group' => $group,
-                                               $wgDisableUserGroupExpiry ?
-                                                       '1' :
-                                                       'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
+                                               'ug_expiry IS NULL OR ug_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() )
                                        ],
                                        __METHOD__
                                );