Migrate some wfWikiId() callers to getLocalDomainID()
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 15 Oct 2018 22:20:50 +0000 (15:20 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 16 Oct 2018 06:58:49 +0000 (23:58 -0700)
Change-Id: I33fe222b7ca66babd61610febaebcf52d3806a7d

includes/GlobalFunctions.php
includes/Title.php
includes/installer/MysqlUpdater.php
includes/jobqueue/JobRunner.php
includes/jobqueue/jobs/RefreshLinksJob.php
includes/user/User.php
tests/phpunit/includes/user/UserTest.php

index b536e69..4531b54 100644 (file)
@@ -2847,15 +2847,19 @@ function wfGetNull() {
 function wfWaitForSlaves(
        $ifWritesSince = null, $wiki = false, $cluster = false, $timeout = null
 ) {
+       $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+
        if ( $cluster === '*' ) {
                $cluster = false;
-               $wiki = false;
+               $domain = false;
        } elseif ( $wiki === false ) {
-               $wiki = wfWikiID();
+               $domain = $lbFactory->getLocalDomainID();
+       } else {
+               $domain = $wiki;
        }
 
        $opts = [
-               'wiki' => $wiki,
+               'domain' => $domain,
                'cluster' => $cluster,
                // B/C: first argument used to be "max seconds of lag"; ignore such values
                'ifWritesSince' => ( $ifWritesSince > 1e9 ) ? $ifWritesSince : null
@@ -2864,7 +2868,6 @@ function wfWaitForSlaves(
                $opts['timeout'] = $timeout;
        }
 
-       $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
        return $lbFactory->waitForReplication( $opts );
 }
 
index de551b4..51d8b13 100644 (file)
@@ -4846,8 +4846,9 @@ class Title implements LinkTarget {
 
                $dbw = wfGetDB( DB_MASTER );
                $dbw->onTransactionPreCommitOrIdle(
-                       function () {
-                               ResourceLoaderWikiModule::invalidateModuleCache( $this, null, null, wfWikiID() );
+                       function () use ( $dbw ) {
+                               ResourceLoaderWikiModule::invalidateModuleCache(
+                                       $this, null, null, $dbw->getDomainId() );
                        },
                        __METHOD__
                );
index a9ca286..82cf7f4 100644 (file)
@@ -931,7 +931,9 @@ class MysqlUpdater extends DatabaseUpdater {
                                if ( $count == 0 ) {
                                        $lbFactory = $services->getDBLoadBalancerFactory();
                                        $lbFactory->waitForReplication( [
-                                               'wiki' => wfWikiID(), 'timeout' => self::REPLICATION_WAIT_TIMEOUT ] );
+                                               'domain' => $lbFactory->getLocalDomainID(),
+                                               'timeout' => self::REPLICATION_WAIT_TIMEOUT
+                                       ] );
                                }
                                $this->db->insert( 'templatelinks',
                                        [
index 1e83167..39b5b3b 100644 (file)
@@ -131,7 +131,7 @@ class JobRunner implements LoggerAwareInterface {
                }
                // Bail out if there is too much DB lag.
                // This check should not block as we want to try other wiki queues.
-               list( , $maxLag ) = $lbFactory->getMainLB( wfWikiID() )->getMaxLag();
+               list( , $maxLag ) = $lbFactory->getMainLB()->getMaxLag();
                if ( $maxLag >= self::MAX_ALLOWED_LAG ) {
                        $response['reached'] = 'replica-lag-limit';
                        return $response;
@@ -536,7 +536,7 @@ class JobRunner implements LoggerAwareInterface {
                $syncThreshold = $this->config->get( 'JobSerialCommitThreshold' );
 
                $time = false;
-               $lb = $lbFactory->getMainLB( wfWikiID() );
+               $lb = $lbFactory->getMainLB();
                if ( $syncThreshold !== false && $lb->getServerCount() > 1 ) {
                        // Generally, there is one master connection to the local DB
                        $dbwSerial = $lb->getAnyOpenConnection( $lb->getWriterIndex() );
index 3488eb6..3f922a3 100644 (file)
@@ -91,7 +91,7 @@ class RefreshLinksJob extends Job {
                        if ( !isset( $this->params['range'] ) ) {
                                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
                                if ( !$lbFactory->waitForReplication( [
-                                               'wiki'    => wfWikiID(),
+                                               'domain'  => $lbFactory->getLocalDomainID(),
                                                'timeout' => self::LAG_WAIT_TIMEOUT
                                ] ) ) { // only try so hard
                                        $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
index fe9a5c9..5e5ca1b 100644 (file)
@@ -492,7 +492,7 @@ class User implements IDBAccessObject, UserIdentity {
         * @param int $userId
         */
        public static function purge( $wikiId, $userId ) {
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                $key = $cache->makeGlobalKey( 'user', 'id', $wikiId, $userId );
                $cache->delete( $key );
        }
@@ -503,7 +503,10 @@ class User implements IDBAccessObject, UserIdentity {
         * @return string
         */
        protected function getCacheKey( WANObjectCache $cache ) {
-               return $cache->makeGlobalKey( 'user', 'id', wfWikiID(), $this->mId );
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+
+               return $cache->makeGlobalKey( 'user', 'id', $lbFactory->getLocalDomainID(), $this->mId );
        }
 
        /**
index cee15e8..1e1f739 100644 (file)
@@ -1015,6 +1015,7 @@ class UserTest extends MediaWikiTestCase {
        }
 
        public function testActorId() {
+               $domain = MediaWikiServices::getInstance()->getDBLoadBalancer()->getLocalDomainID();
                $this->hideDeprecated( 'User::selectFields' );
 
                // Newly-created user has an actor ID
@@ -1042,7 +1043,7 @@ class UserTest extends MediaWikiTestCase {
                        'Actor ID can be retrieved for user loaded with User::selectFields()' );
 
                $this->db->delete( 'actor', [ 'actor_user' => $id ], __METHOD__ );
-               User::purge( wfWikiId(), $id );
+               User::purge( $domain, $id );
                // Because WANObjectCache->delete() stupidly doesn't delete from the process cache.
                ObjectCache::getMainWANInstance()->clearProcessCache();