X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FWatchedItemStore.php;h=c4340ad5e1f6bc33f19215f8eb1ce238d288317b;hb=12e2e9edbc5f97b49d85194af5fff316d5bf4a90;hp=4eea54deecaf240d1ac95bfadcd6c7de935fbdde;hpb=5a0da02e6a42da80035d7b3591e257c0c995e5e3;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index 4eea54deec..c4340ad5e1 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -615,30 +615,30 @@ class WatchedItemStore { * @param LinkTarget $target */ public function addWatch( User $user, LinkTarget $target ) { - $this->addWatchBatch( [ [ $user, $target ] ] ); + $this->addWatchBatchForUser( $user, [ $target ] ); } /** - * @param array[] $userTargetCombinations array of arrays containing [0] => User [1] => LinkTarget + * @param User $user + * @param LinkTarget[] $targets * * @return bool success */ - public function addWatchBatch( array $userTargetCombinations ) { + public function addWatchBatchForUser( User $user, array $targets ) { if ( $this->loadBalancer->getReadOnlyReason() !== false ) { return false; } + // Only loggedin user can have a watchlist + if ( $user->isAnon() ) { + return false; + } + + if ( !$targets ) { + return true; + } $rows = []; - foreach ( $userTargetCombinations as list( $user, $target ) ) { - /** - * @var User $user - * @var LinkTarget $target - */ - - // Only loggedin user can have a watchlist - if ( $user->isAnon() ) { - continue; - } + foreach ( $targets as $target ) { $rows[] = [ 'wl_user' => $user->getId(), 'wl_namespace' => $target->getNamespace(), @@ -648,10 +648,6 @@ class WatchedItemStore { $this->uncache( $user, $target ); } - if ( !$rows ) { - return false; - } - $dbw = $this->getConnection( DB_MASTER ); foreach ( array_chunk( $rows, 100 ) as $toInsert ) { // Use INSERT IGNORE to avoid overwriting the notification timestamp