Category.php - add a variable $loadBalancer instead of calling wfGetDB
Change-Id: I80bbfb77904d30eda4042755eb4c9398ee74c296
This commit is contained in:
parent
aa6b910b7a
commit
fa42bf5639
1 changed files with 11 additions and 4 deletions
|
|
@ -21,6 +21,9 @@
|
|||
* @author Simetrical
|
||||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
* Category objects are immutable, strictly speaking. If you call methods that change the database,
|
||||
* like to refresh link counts, the objects will be appropriately reinitialized.
|
||||
|
|
@ -43,7 +46,11 @@ class Category {
|
|||
|
||||
public const ROW_COUNT_SMALL = 100;
|
||||
|
||||
/** @var ILoadBalancer */
|
||||
private $loadBalancer;
|
||||
|
||||
private function __construct() {
|
||||
$this->loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,7 +71,7 @@ class Category {
|
|||
return true;
|
||||
}
|
||||
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$dbr = $this->loadBalancer->getConnectionRef( DB_REPLICA );
|
||||
$row = $dbr->selectRow(
|
||||
'category',
|
||||
[ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ],
|
||||
|
|
@ -269,7 +276,7 @@ class Category {
|
|||
* @return TitleArray TitleArray object for category members.
|
||||
*/
|
||||
public function getMembers( $limit = false, $offset = '' ) {
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$dbr = $this->loadBalancer->getConnectionRef( DB_REPLICA );
|
||||
|
||||
$conds = [ 'cl_to' => $this->getName(), 'cl_from = page_id' ];
|
||||
$options = [ 'ORDER BY' => 'cl_sortkey' ];
|
||||
|
|
@ -325,7 +332,7 @@ class Category {
|
|||
return false;
|
||||
}
|
||||
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
$dbw = $this->loadBalancer->getConnectionRef( DB_MASTER );
|
||||
# Avoid excess contention on the same category (T162121)
|
||||
$name = __METHOD__ . ':' . md5( $this->mName );
|
||||
$scopedLock = $dbw->getScopedLockAndFlush( $name, __METHOD__, 0 );
|
||||
|
|
@ -450,7 +457,7 @@ class Category {
|
|||
* @since 1.34
|
||||
*/
|
||||
public function refreshCountsIfSmall( $maxSize = self::ROW_COUNT_SMALL ) {
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
$dbw = $this->loadBalancer->getConnectionRef( DB_MASTER );
|
||||
$dbw->startAtomic( __METHOD__ );
|
||||
|
||||
$typeOccurances = $dbw->selectFieldValues(
|
||||
|
|
|
|||
Loading…
Reference in a new issue