/**
* @param int $dbIndex DB_MASTER or DB_REPLICA
*
- * @return DatabaseBase
+ * @return IDatabase
* @throws MWException
*/
- private function getConnection( $dbIndex ) {
- return $this->loadBalancer->getConnection( $dbIndex, [ 'watchlist' ] );
- }
-
- /**
- * @param Database $connection
- *
- * @throws MWException
- */
- private function reuseConnection( $connection ) {
- $this->loadBalancer->reuseConnection( $connection );
+ private function getConnectionRef( $dbIndex ) {
+ return $this->loadBalancer->getConnectionRef( $dbIndex, [ 'watchlist' ] );
}
/**
* @return int
*/
public function countWatchedItems( User $user ) {
- $dbr = $this->getConnection( DB_REPLICA );
+ $dbr = $this->getConnectionRef( DB_REPLICA );
$return = (int)$dbr->selectField(
'watchlist',
'COUNT(*)',
],
__METHOD__
);
- $this->reuseConnection( $dbr );
return $return;
}
* @return int
*/
public function countWatchers( LinkTarget $target ) {
- $dbr = $this->getConnection( DB_REPLICA );
+ $dbr = $this->getConnectionRef( DB_REPLICA );
$return = (int)$dbr->selectField(
'watchlist',
'COUNT(*)',
],
__METHOD__
);
- $this->reuseConnection( $dbr );
return $return;
}
* @throws MWException
*/
public function countVisitingWatchers( LinkTarget $target, $threshold ) {
- $dbr = $this->getConnection( DB_REPLICA );
+ $dbr = $this->getConnectionRef( DB_REPLICA );
$visitingWatchers = (int)$dbr->selectField(
'watchlist',
'COUNT(*)',
],
__METHOD__
);
- $this->reuseConnection( $dbr );
return $visitingWatchers;
}
public function countWatchersMultiple( array $targets, array $options = [] ) {
$dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
- $dbr = $this->getConnection( DB_REPLICA );
+ $dbr = $this->getConnectionRef( DB_REPLICA );
if ( array_key_exists( 'minimumWatchers', $options ) ) {
$dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$options['minimumWatchers'];
$dbOptions
);
- $this->reuseConnection( $dbr );
-
$watchCounts = [];
foreach ( $targets as $linkTarget ) {
$watchCounts[$linkTarget->getNamespace()][$linkTarget->getDBkey()] = 0;
array $targetsWithVisitThresholds,
$minimumWatchers = null
) {
- $dbr = $this->getConnection( DB_REPLICA );
+ $dbr = $this->getConnectionRef( DB_REPLICA );
$conds = $this->getVisitingWatchersCondition( $dbr, $targetsWithVisitThresholds );
$dbOptions
);
- $this->reuseConnection( $dbr );
-
$watcherCounts = [];
foreach ( $targetsWithVisitThresholds as list( $target ) ) {
/* @var LinkTarget $target */
return false;
}
- $dbr = $this->getConnection( DB_REPLICA );
+ $dbr = $this->getConnectionRef( DB_REPLICA );
$row = $dbr->selectRow(
'watchlist',
'wl_notificationtimestamp',
$this->dbCond( $user, $target ),
__METHOD__
);
- $this->reuseConnection( $dbr );
if ( !$row ) {
return false;
"wl_title {$options['sort']}"
];
}
- $db = $this->getConnection( $options['forWrite'] ? DB_MASTER : DB_REPLICA );
+ $db = $this->getConnectionRef( $options['forWrite'] ? DB_MASTER : DB_REPLICA );
$res = $db->select(
'watchlist',
__METHOD__,
$dbOptions
);
- $this->reuseConnection( $db );
$watchedItems = [];
foreach ( $res as $row ) {
return $timestamps;
}
- $dbr = $this->getConnection( DB_REPLICA );
+ $dbr = $this->getConnectionRef( DB_REPLICA );
$lb = new LinkBatch( $targetsToLoad );
$res = $dbr->select(
],
__METHOD__
);
- $this->reuseConnection( $dbr );
foreach ( $res as $row ) {
$timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp;
$this->uncache( $user, $target );
}
- $dbw = $this->getConnection( DB_MASTER );
+ $dbw = $this->getConnectionRef( DB_MASTER );
foreach ( array_chunk( $rows, 100 ) as $toInsert ) {
// Use INSERT IGNORE to avoid overwriting the notification timestamp
// if there's already an entry for this page
$dbw->insert( 'watchlist', $toInsert, __METHOD__, 'IGNORE' );
}
- $this->reuseConnection( $dbw );
return true;
}
$this->uncache( $user, $target );
- $dbw = $this->getConnection( DB_MASTER );
+ $dbw = $this->getConnectionRef( DB_MASTER );
$dbw->delete( 'watchlist',
[
'wl_user' => $user->getId(),
], __METHOD__
);
$success = (bool)$dbw->affectedRows();
- $this->reuseConnection( $dbw );
return $success;
}
return false;
}
- $dbw = $this->getConnection( DB_MASTER );
+ $dbw = $this->getConnectionRef( DB_MASTER );
$conds = [ 'wl_user' => $user->getId() ];
if ( $targets ) {
__METHOD__
);
- $this->reuseConnection( $dbw );
-
$this->uncacheUser( $user );
return $success;
* @return int[] Array of user IDs the timestamp has been updated for
*/
public function updateNotificationTimestamp( User $editor, LinkTarget $target, $timestamp ) {
- $dbw = $this->getConnection( DB_MASTER );
+ $dbw = $this->getConnectionRef( DB_MASTER );
$uids = $dbw->selectFieldValues(
'watchlist',
'wl_user',
],
__METHOD__
);
- $this->reuseConnection( $dbw );
$watchers = array_map( 'intval', $uids );
if ( $watchers ) {
function () use ( $timestamp, $watchers, $target, $fname ) {
global $wgUpdateRowsPerQuery;
- $dbw = $this->getConnection( DB_MASTER );
+ $dbw = $this->getConnectionRef( DB_MASTER );
$factory = wfGetLBFactory();
$ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
}
}
$this->uncacheLinkTarget( $target );
-
- $this->reuseConnection( $dbw );
},
DeferredUpdates::POSTSEND,
$dbw
$queryOptions['LIMIT'] = $unreadLimit;
}
- $dbr = $this->getConnection( DB_REPLICA );
+ $dbr = $this->getConnectionRef( DB_REPLICA );
$rowCount = $dbr->selectRowCount(
'watchlist',
'1',
__METHOD__,
$queryOptions
);
- $this->reuseConnection( $dbr );
if ( !isset( $unreadLimit ) ) {
return $rowCount;
* @param LinkTarget $newTarget
*/
public function duplicateEntry( LinkTarget $oldTarget, LinkTarget $newTarget ) {
- $dbw = $this->getConnection( DB_MASTER );
+ $dbw = $this->getConnectionRef( DB_MASTER );
$result = $dbw->select(
'watchlist',
__METHOD__
);
}
-
- $this->reuseConnection( $dbw );
}
}