X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FWatchedItemStore.php;h=9a74401a4304ca214f2100eadc806f78174b1fdb;hb=24ac34ef9778487c02c58c40ef7cf5b2d7380f91;hp=89ca50c00b2efe5b2f083fb62717e2fccae08060;hpb=b86ef89dd17f51841a220e8ef9b3b8b2402e2547;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index 89ca50c00b..9a74401a43 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -190,13 +190,13 @@ class WatchedItemStore implements StatsdAwareInterface { } /** - * @param int $slaveOrMaster DB_MASTER or DB_SLAVE + * @param int $dbIndex DB_MASTER or DB_REPLICA * * @return DatabaseBase * @throws MWException */ - private function getConnection( $slaveOrMaster ) { - return $this->loadBalancer->getConnection( $slaveOrMaster, [ 'watchlist' ] ); + private function getConnection( $dbIndex ) { + return $this->loadBalancer->getConnection( $dbIndex, [ 'watchlist' ] ); } /** @@ -217,7 +217,7 @@ class WatchedItemStore implements StatsdAwareInterface { * @return int */ public function countWatchedItems( User $user ) { - $dbr = $this->getConnection( DB_SLAVE ); + $dbr = $this->getConnection( DB_REPLICA ); $return = (int)$dbr->selectField( 'watchlist', 'COUNT(*)', @@ -237,7 +237,7 @@ class WatchedItemStore implements StatsdAwareInterface { * @return int */ public function countWatchers( LinkTarget $target ) { - $dbr = $this->getConnection( DB_SLAVE ); + $dbr = $this->getConnection( DB_REPLICA ); $return = (int)$dbr->selectField( 'watchlist', 'COUNT(*)', @@ -263,7 +263,7 @@ class WatchedItemStore implements StatsdAwareInterface { * @throws MWException */ public function countVisitingWatchers( LinkTarget $target, $threshold ) { - $dbr = $this->getConnection( DB_SLAVE ); + $dbr = $this->getConnection( DB_REPLICA ); $visitingWatchers = (int)$dbr->selectField( 'watchlist', 'COUNT(*)', @@ -293,7 +293,7 @@ class WatchedItemStore implements StatsdAwareInterface { public function countWatchersMultiple( array $targets, array $options = [] ) { $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ]; - $dbr = $this->getConnection( DB_SLAVE ); + $dbr = $this->getConnection( DB_REPLICA ); if ( array_key_exists( 'minimumWatchers', $options ) ) { $dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$options['minimumWatchers']; @@ -341,7 +341,7 @@ class WatchedItemStore implements StatsdAwareInterface { array $targetsWithVisitThresholds, $minimumWatchers = null ) { - $dbr = $this->getConnection( DB_SLAVE ); + $dbr = $this->getConnection( DB_REPLICA ); $conds = $this->getVisitingWatchersCondition( $dbr, $targetsWithVisitThresholds ); @@ -452,7 +452,7 @@ class WatchedItemStore implements StatsdAwareInterface { return false; } - $dbr = $this->getConnection( DB_SLAVE ); + $dbr = $this->getConnection( DB_REPLICA ); $row = $dbr->selectRow( 'watchlist', 'wl_notificationtimestamp', @@ -499,7 +499,7 @@ class WatchedItemStore implements StatsdAwareInterface { "wl_title {$options['sort']}" ]; } - $db = $this->getConnection( $options['forWrite'] ? DB_MASTER : DB_SLAVE ); + $db = $this->getConnection( $options['forWrite'] ? DB_MASTER : DB_REPLICA ); $res = $db->select( 'watchlist', @@ -569,7 +569,7 @@ class WatchedItemStore implements StatsdAwareInterface { return $timestamps; } - $dbr = $this->getConnection( DB_SLAVE ); + $dbr = $this->getConnection( DB_REPLICA ); $lb = new LinkBatch( $targetsToLoad ); $res = $dbr->select( @@ -741,6 +741,8 @@ class WatchedItemStore implements StatsdAwareInterface { global $wgUpdateRowsPerQuery; $dbw = $this->getConnection( DB_MASTER ); + $factory = wfGetLBFactory(); + $ticket = $factory->getEmptyTransactionTicket( __METHOD__ ); $watchersChunks = array_chunk( $watchers, $wgUpdateRowsPerQuery ); foreach ( $watchersChunks as $watchersChunk ) { @@ -754,14 +756,17 @@ class WatchedItemStore implements StatsdAwareInterface { ], $fname ); if ( count( $watchersChunks ) > 1 ) { - $dbw->commit( __METHOD__, 'flush' ); - wfGetLBFactory()->waitForReplication( [ 'wiki' => $dbw->getWikiID() ] ); + $factory->commitAndWaitForReplication( + __METHOD__, $ticket, [ 'wiki' => $dbw->getWikiID() ] + ); } } $this->uncacheLinkTarget( $target ); $this->reuseConnection( $dbw ); - } + }, + DeferredUpdates::POSTSEND, + $dbw ); } @@ -880,7 +885,7 @@ class WatchedItemStore implements StatsdAwareInterface { $queryOptions['LIMIT'] = $unreadLimit; } - $dbr = $this->getConnection( DB_SLAVE ); + $dbr = $this->getConnection( DB_REPLICA ); $rowCount = $dbr->selectRowCount( 'watchlist', '1',