];
}
+ /**
+ * @param int $slaveOrMaster DB_MASTER or DB_SLAVE
+ *
+ * @return DatabaseBase
+ * @throws MWException
+ */
+ private function getConnection( $slaveOrMaster ) {
+ return $this->loadBalancer->getConnection( $slaveOrMaster, [ 'watchlist' ] );
+ }
+
+ /**
+ * @param DatabaseBase $connection
+ *
+ * @throws MWException
+ */
+ private function reuseConnection( $connection ) {
+ $this->loadBalancer->reuseConnection( $connection );
+ }
+
/**
* @param LinkTarget $target
*
* @return int
*/
public function countWatchers( LinkTarget $target ) {
- $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 'watchlist' ] );
+ $dbr = $this->getConnection( DB_SLAVE );
$return = (int)$dbr->selectField(
'watchlist',
'COUNT(*)',
],
__METHOD__
);
- $this->loadBalancer->reuseConnection( $dbr );
+ $this->reuseConnection( $dbr );
return $return;
}
* @throws MWException
*/
public function countVisitingWatchers( LinkTarget $target, $threshold ) {
- $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 'watchlist' ] );
+ $dbr = $this->getConnection( DB_SLAVE );
$visitingWatchers = (int)$dbr->selectField(
'watchlist',
'COUNT(*)',
],
__METHOD__
);
- $this->loadBalancer->reuseConnection( $dbr );
+ $this->reuseConnection( $dbr );
return $visitingWatchers;
}
public function countWatchersMultiple( array $targets, array $options = [] ) {
$dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
- $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 'watchlist' ] );
+ $dbr = $this->getConnection( DB_SLAVE );
if ( array_key_exists( 'minimumWatchers', $options ) ) {
$dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$options['minimumWatchers'];
$dbOptions
);
- $this->loadBalancer->reuseConnection( $dbr );
+ $this->reuseConnection( $dbr );
$watchCounts = [];
foreach ( $targets as $linkTarget ) {
return false;
}
- $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 'watchlist' ] );
+ $dbr = $this->getConnection( DB_SLAVE );
$row = $dbr->selectRow(
'watchlist',
'wl_notificationtimestamp',
$this->dbCond( $user, $target ),
__METHOD__
);
- $this->loadBalancer->reuseConnection( $dbr );
+ $this->reuseConnection( $dbr );
if ( !$row ) {
return false;
return false;
}
- $dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 'watchlist' ] );
+ $dbw = $this->getConnection( 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->loadBalancer->reuseConnection( $dbw );
+ $this->reuseConnection( $dbw );
return true;
}
$this->uncache( $user, $target );
- $dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 'watchlist' ] );
+ $dbw = $this->getConnection( DB_MASTER );
$dbw->delete( 'watchlist',
[
'wl_user' => $user->getId(),
], __METHOD__
);
$success = (bool)$dbw->affectedRows();
- $this->loadBalancer->reuseConnection( $dbw );
+ $this->reuseConnection( $dbw );
return $success;
}
* @return int[] Array of user IDs the timestamp has been updated for
*/
public function updateNotificationTimestamp( User $editor, LinkTarget $target, $timestamp ) {
- $dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 'watchlist' ] );
+ $dbw = $this->getConnection( DB_MASTER );
$res = $dbw->select( [ 'watchlist' ],
[ 'wl_user' ],
[
);
}
- $this->loadBalancer->reuseConnection( $dbw );
+ $this->reuseConnection( $dbw );
return $watchers;
}
$queryOptions['LIMIT'] = $unreadLimit;
}
- $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [ 'watchlist' ] );
+ $dbr = $this->getConnection( DB_SLAVE );
$rowCount = $dbr->selectRowCount(
'watchlist',
'1',
__METHOD__,
$queryOptions
);
- $this->loadBalancer->reuseConnection( $dbr );
+ $this->reuseConnection( $dbr );
if ( !isset( $unreadLimit ) ) {
return $rowCount;
* @param LinkTarget $newTarget
*/
public function duplicateEntry( LinkTarget $oldTarget, LinkTarget $newTarget ) {
- $dbw = $this->loadBalancer->getConnection( DB_MASTER, [ 'watchlist' ] );
+ $dbw = $this->getConnection( DB_MASTER );
$result = $dbw->select(
'watchlist',
);
}
- $this->loadBalancer->reuseConnection( $dbw );
+ $this->reuseConnection( $dbw );
}
}