From ebbccf1845abbd1030ce8e3c7d27c2014f2b66ce Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 15 Oct 2018 15:20:50 -0700 Subject: [PATCH] Migrate some wfWikiId() callers to getLocalDomainID() Change-Id: I33fe222b7ca66babd61610febaebcf52d3806a7d --- includes/GlobalFunctions.php | 11 +++++++---- includes/Title.php | 5 +++-- includes/installer/MysqlUpdater.php | 4 +++- includes/jobqueue/JobRunner.php | 4 ++-- includes/jobqueue/jobs/RefreshLinksJob.php | 2 +- includes/user/User.php | 7 +++++-- tests/phpunit/includes/user/UserTest.php | 3 ++- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index b536e694db..4531b5401b 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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 ); } diff --git a/includes/Title.php b/includes/Title.php index de551b4d23..51d8b1355c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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__ ); diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index a9ca28614d..82cf7f429d 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -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', [ diff --git a/includes/jobqueue/JobRunner.php b/includes/jobqueue/JobRunner.php index 1e8316795c..39b5b3bee4 100644 --- a/includes/jobqueue/JobRunner.php +++ b/includes/jobqueue/JobRunner.php @@ -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() ); diff --git a/includes/jobqueue/jobs/RefreshLinksJob.php b/includes/jobqueue/jobs/RefreshLinksJob.php index 3488eb6309..3f922a3f6a 100644 --- a/includes/jobqueue/jobs/RefreshLinksJob.php +++ b/includes/jobqueue/jobs/RefreshLinksJob.php @@ -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(); diff --git a/includes/user/User.php b/includes/user/User.php index fe9a5c9ebb..5e5ca1b6f7 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -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 ); } /** diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index cee15e82c8..1e1f7392c5 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -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(); -- 2.20.1