Alter use of deprecated methods to ones called 'Primary'

This extension already depends on MW 1.37, so all these methods exist.

Bug: T254646
Depends-On: I9a90b4f74eb65cd9e20ae9faa6d1949be96543c0
Change-Id: Iebfdd33d3a967c87fbf87382a010a01da5cd4fc8
This commit is contained in:
James D. Forrester 2021-09-03 17:46:13 -07:00
parent 454f6037bb
commit a47a421696
3 changed files with 38 additions and 38 deletions

View file

@ -138,7 +138,7 @@ class MWEchoDbFactory {
* Wait for the replicas of the database
*/
public function waitForReplicas() {
$this->waitFor( $this->getMasterPosition() );
$this->waitFor( $this->getPrimaryPosition() );
}
/**
@ -147,20 +147,20 @@ class MWEchoDbFactory {
*
* @return array
*/
public function getMasterPosition() {
public function getPrimaryPosition() {
$position = [
'wikiDb' => false,
'echoDb' => false,
];
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
if ( $lb->getServerCount() > 1 ) {
$position['wikiDb'] = $lb->getMasterPos();
$position['wikiDb'] = $lb->getPrimaryPos();
}
if ( $this->cluster ) {
$lb = $this->getLB();
if ( $lb->getServerCount() > 1 ) {
$position['echoDb'] = $lb->getMasterPos();
$position['echoDb'] = $lb->getPrimaryPos();
}
}
@ -168,7 +168,7 @@ class MWEchoDbFactory {
}
/**
* Receives the output of self::getMasterPosition. Waits
* Receives the output of self::getPrimaryPosition. Waits
* for replicas to catch up to the primary database position at that
* point.
*
@ -187,7 +187,7 @@ class MWEchoDbFactory {
* Check whether it makes sense to retry a failed lookup on the primary database.
* @return bool True if there are multiple servers and changes were made in this request; false otherwise
*/
public function canRetryMaster() {
return $this->getLB()->getServerCount() > 1 && $this->getLB()->hasOrMadeRecentMasterChanges();
public function canRetryPrimary() {
return $this->getLB()->getServerCount() > 1 && $this->getLB()->hasOrMadeRecentPrimaryChanges();
}
}

View file

@ -452,32 +452,32 @@ class ApiEchoNotifications extends ApiQueryBase {
* @return array
*/
protected function mergeResults( array $results, array $params ) {
$master = array_shift( $results );
if ( !$master ) {
$master = [];
$primary = array_shift( $results );
if ( !$primary ) {
$primary = [];
}
if ( in_array( 'list', $params['prop'] ) ) {
$master = $this->mergeList( $master, $results, $params['groupbysection'] );
$primary = $this->mergeList( $primary, $results, $params['groupbysection'] );
}
if ( in_array( 'count', $params['prop'] ) && !$this->crossWikiSummary ) {
// if crosswiki data was requested, the count in $master
// if crosswiki data was requested, the count in $primary
// is accurate already
// otherwise, we'll want to combine counts for all wikis
$master = $this->mergeCount( $master, $results, $params['groupbysection'] );
$primary = $this->mergeCount( $primary, $results, $params['groupbysection'] );
}
return $master;
return $primary;
}
/**
* @param array $master
* @param array $primary
* @param array[] $results
* @param bool $groupBySection
* @return array
*/
protected function mergeList( array $master, array $results, $groupBySection ) {
protected function mergeList( array $primary, array $results, $groupBySection ) {
// sort all notifications by timestamp: most recent first
$sort = static function ( $a, $b ) {
return $a['timestamp']['utcunix'] - $b['timestamp']['utcunix'];
@ -485,57 +485,57 @@ class ApiEchoNotifications extends ApiQueryBase {
if ( $groupBySection ) {
foreach ( EchoAttributeManager::$sections as $section ) {
if ( !isset( $master[$section]['list'] ) ) {
$master[$section]['list'] = [];
if ( !isset( $primary[$section]['list'] ) ) {
$primary[$section]['list'] = [];
}
foreach ( $results as $result ) {
$master[$section]['list'] = array_merge( $master[$section]['list'], $result[$section]['list'] );
$primary[$section]['list'] = array_merge( $primary[$section]['list'], $result[$section]['list'] );
}
usort( $master[$section]['list'], $sort );
usort( $primary[$section]['list'], $sort );
}
} else {
if ( !isset( $master['list'] ) || !is_array( $master['list'] ) ) {
$master['list'] = [];
if ( !isset( $primary['list'] ) || !is_array( $primary['list'] ) ) {
$primary['list'] = [];
}
foreach ( $results as $result ) {
$master['list'] = array_merge( $master['list'], $result['list'] );
$primary['list'] = array_merge( $primary['list'], $result['list'] );
}
usort( $master['list'], $sort );
usort( $primary['list'], $sort );
}
return $master;
return $primary;
}
/**
* @param array $master
* @param array $primary
* @param array[] $results
* @param bool $groupBySection
* @return array
*/
protected function mergeCount( array $master, array $results, $groupBySection ) {
protected function mergeCount( array $primary, array $results, $groupBySection ) {
if ( $groupBySection ) {
foreach ( EchoAttributeManager::$sections as $section ) {
if ( !isset( $master[$section]['rawcount'] ) ) {
$master[$section]['rawcount'] = 0;
if ( !isset( $primary[$section]['rawcount'] ) ) {
$primary[$section]['rawcount'] = 0;
}
foreach ( $results as $result ) {
$master[$section]['rawcount'] += $result[$section]['rawcount'];
$primary[$section]['rawcount'] += $result[$section]['rawcount'];
}
$master[$section]['count'] = EchoNotificationController::formatNotificationCount(
$master[$section]['rawcount'] );
$primary[$section]['count'] = EchoNotificationController::formatNotificationCount(
$primary[$section]['rawcount'] );
}
}
if ( !isset( $master['rawcount'] ) ) {
$master['rawcount'] = 0;
if ( !isset( $primary['rawcount'] ) ) {
$primary['rawcount'] = 0;
}
foreach ( $results as $result ) {
// regardless of groupbysection, totals are always included
$master['rawcount'] += $result['rawcount'];
$primary['rawcount'] += $result['rawcount'];
}
$master['count'] = EchoNotificationController::formatNotificationCount( $master['rawcount'] );
$primary['count'] = EchoNotificationController::formatNotificationCount( $primary['rawcount'] );
return $master;
return $primary;
}
public function getAllowedParams() {

View file

@ -45,7 +45,7 @@ class EchoEventMapper extends EchoAbstractMapper {
$row = $db->selectRow( 'echo_event', EchoEvent::selectFields(), [ 'event_id' => $id ], __METHOD__ );
// If the row was not found, fall back on the primary database if it makes sense to do so
if ( !$row && !$fromPrimary && $this->dbFactory->canRetryMaster() ) {
if ( !$row && !$fromPrimary && $this->dbFactory->canRetryPrimary() ) {
return $this->fetchById( $id, true );
} elseif ( !$row ) {
throw new MWException( "No EchoEvent found with ID: $id" );