3 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface
;
4 use Wikimedia\Assert\Assert
;
7 * Storage layer class for WatchedItems.
8 * Database interaction.
14 class WatchedItemStore
{
16 const SORT_DESC
= 'DESC';
17 const SORT_ASC
= 'ASC';
22 private $loadBalancer;
30 * @var array[] Looks like $cacheIndex[Namespace ID][Target DB Key][User Id] => 'key'
31 * The index is needed so that on mass changes all relevant items can be un-cached.
32 * For example: Clearing a users watchlist of all items or updating notification timestamps
33 * for all users watching a single target.
35 private $cacheIndex = [];
40 private $deferredUpdatesAddCallableUpdateCallback;
45 private $revisionGetTimestampFromIdCallback;
48 * @var StatsdDataFactoryInterface
55 private static $instance;
58 * @param LoadBalancer $loadBalancer
59 * @param HashBagOStuff $cache
60 * @param StatsdDataFactoryInterface $stats
62 public function __construct(
63 LoadBalancer
$loadBalancer,
65 StatsdDataFactoryInterface
$stats
67 $this->loadBalancer
= $loadBalancer;
68 $this->cache
= $cache;
69 $this->stats
= $stats;
70 $this->deferredUpdatesAddCallableUpdateCallback
= [ 'DeferredUpdates', 'addCallableUpdate' ];
71 $this->revisionGetTimestampFromIdCallback
= [ 'Revision', 'getTimestampFromId' ];
75 * Overrides the DeferredUpdates::addCallableUpdate callback
76 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
78 * @param callable $callback
80 * @see DeferredUpdates::addCallableUpdate for callback signiture
82 * @return ScopedCallback to reset the overridden value
85 public function overrideDeferredUpdatesAddCallableUpdateCallback( $callback ) {
86 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
87 throw new MWException(
88 'Cannot override DeferredUpdates::addCallableUpdate callback in operation.'
91 Assert
::parameterType( 'callable', $callback, '$callback' );
93 $previousValue = $this->deferredUpdatesAddCallableUpdateCallback
;
94 $this->deferredUpdatesAddCallableUpdateCallback
= $callback;
95 return new ScopedCallback( function() use ( $previousValue ) {
96 $this->deferredUpdatesAddCallableUpdateCallback
= $previousValue;
101 * Overrides the Revision::getTimestampFromId callback
102 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
104 * @param callable $callback
105 * @see Revision::getTimestampFromId for callback signiture
107 * @return ScopedCallback to reset the overridden value
108 * @throws MWException
110 public function overrideRevisionGetTimestampFromIdCallback( $callback ) {
111 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
112 throw new MWException(
113 'Cannot override Revision::getTimestampFromId callback in operation.'
116 Assert
::parameterType( 'callable', $callback, '$callback' );
118 $previousValue = $this->revisionGetTimestampFromIdCallback
;
119 $this->revisionGetTimestampFromIdCallback
= $callback;
120 return new ScopedCallback( function() use ( $previousValue ) {
121 $this->revisionGetTimestampFromIdCallback
= $previousValue;
126 * Overrides the default instance of this class
127 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
129 * If this method is used it MUST also be called with null after a test to ensure a new
130 * default instance is created next time getDefaultInstance is called.
132 * @param WatchedItemStore|null $store
134 * @return ScopedCallback to reset the overridden value
135 * @throws MWException
137 public static function overrideDefaultInstance( WatchedItemStore
$store = null ) {
138 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
139 throw new MWException(
140 'Cannot override ' . __CLASS__
. 'default instance in operation.'
144 $previousValue = self
::$instance;
145 self
::$instance = $store;
146 return new ScopedCallback( function() use ( $previousValue ) {
147 self
::$instance = $previousValue;
154 public static function getDefaultInstance() {
155 if ( !self
::$instance ) {
156 self
::$instance = new self(
158 new HashBagOStuff( [ 'maxKeys' => 100 ] ),
159 RequestContext
::getMain()->getStats()
162 return self
::$instance;
165 private function getCacheKey( User
$user, LinkTarget
$target ) {
166 return $this->cache
->makeKey(
167 (string)$target->getNamespace(),
169 (string)$user->getId()
173 private function cache( WatchedItem
$item ) {
174 $user = $item->getUser();
175 $target = $item->getLinkTarget();
176 $key = $this->getCacheKey( $user, $target );
177 $this->cache
->set( $key, $item );
178 $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()][$user->getId()] = $key;
179 $this->stats
->increment( 'WatchedItemStore.cache' );
182 private function uncache( User
$user, LinkTarget
$target ) {
183 $this->cache
->delete( $this->getCacheKey( $user, $target ) );
184 unset( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()][$user->getId()] );
185 $this->stats
->increment( 'WatchedItemStore.uncache' );
188 private function uncacheLinkTarget( LinkTarget
$target ) {
189 if ( !isset( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()] ) ) {
192 $this->stats
->increment( 'WatchedItemStore.uncacheLinkTarget' );
193 foreach ( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()] as $key ) {
194 $this->stats
->increment( 'WatchedItemStore.uncacheLinkTarget.items' );
195 $this->cache
->delete( $key );
201 * @param LinkTarget $target
203 * @return WatchedItem|null
205 private function getCached( User
$user, LinkTarget
$target ) {
206 return $this->cache
->get( $this->getCacheKey( $user, $target ) );
210 * Return an array of conditions to select or update the appropriate database
214 * @param LinkTarget $target
218 private function dbCond( User
$user, LinkTarget
$target ) {
220 'wl_user' => $user->getId(),
221 'wl_namespace' => $target->getNamespace(),
222 'wl_title' => $target->getDBkey(),
227 * @param int $slaveOrMaster DB_MASTER or DB_SLAVE
229 * @return DatabaseBase
230 * @throws MWException
232 private function getConnection( $slaveOrMaster ) {
233 return $this->loadBalancer
->getConnection( $slaveOrMaster, [ 'watchlist' ] );
237 * @param DatabaseBase $connection
239 * @throws MWException
241 private function reuseConnection( $connection ) {
242 $this->loadBalancer
->reuseConnection( $connection );
246 * Count the number of individual items that are watched by the user.
247 * If a subject and corresponding talk page are watched this will return 2.
253 public function countWatchedItems( User
$user ) {
254 $dbr = $this->getConnection( DB_SLAVE
);
255 $return = (int)$dbr->selectField(
259 'wl_user' => $user->getId()
263 $this->reuseConnection( $dbr );
269 * @param LinkTarget $target
273 public function countWatchers( LinkTarget
$target ) {
274 $dbr = $this->getConnection( DB_SLAVE
);
275 $return = (int)$dbr->selectField(
279 'wl_namespace' => $target->getNamespace(),
280 'wl_title' => $target->getDBkey(),
284 $this->reuseConnection( $dbr );
290 * Number of page watchers who also visited a "recent" edit
292 * @param LinkTarget $target
293 * @param mixed $threshold timestamp accepted by wfTimestamp
296 * @throws DBUnexpectedError
297 * @throws MWException
299 public function countVisitingWatchers( LinkTarget
$target, $threshold ) {
300 $dbr = $this->getConnection( DB_SLAVE
);
301 $visitingWatchers = (int)$dbr->selectField(
305 'wl_namespace' => $target->getNamespace(),
306 'wl_title' => $target->getDBkey(),
307 'wl_notificationtimestamp >= ' .
308 $dbr->addQuotes( $dbr->timestamp( $threshold ) ) .
309 ' OR wl_notificationtimestamp IS NULL'
313 $this->reuseConnection( $dbr );
315 return $visitingWatchers;
319 * @param LinkTarget[] $targets
320 * @param array $options Allowed keys:
321 * 'minimumWatchers' => int
323 * @return array multi dimensional like $return[$namespaceId][$titleString] = int $watchers
324 * All targets will be present in the result. 0 either means no watchers or the number
325 * of watchers was below the minimumWatchers option if passed.
327 public function countWatchersMultiple( array $targets, array $options = [] ) {
328 $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
330 $dbr = $this->getConnection( DB_SLAVE
);
332 if ( array_key_exists( 'minimumWatchers', $options ) ) {
333 $dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$options['minimumWatchers'];
336 $lb = new LinkBatch( $targets );
339 [ 'wl_title', 'wl_namespace', 'watchers' => 'COUNT(*)' ],
340 [ $lb->constructSet( 'wl', $dbr ) ],
345 $this->reuseConnection( $dbr );
348 foreach ( $targets as $linkTarget ) {
349 $watchCounts[$linkTarget->getNamespace()][$linkTarget->getDBkey()] = 0;
352 foreach ( $res as $row ) {
353 $watchCounts[$row->wl_namespace
][$row->wl_title
] = (int)$row->watchers
;
360 * Number of watchers of each page who have visited recent edits to that page
362 * @param array $targetsWithVisitThresholds array of pairs (LinkTarget $target, mixed $threshold),
364 * - a timestamp of the recent edit if $target exists (format accepted by wfTimestamp)
365 * - null if $target doesn't exist
366 * @param int|null $minimumWatchers
367 * @return array multi-dimensional like $return[$namespaceId][$titleString] = $watchers,
368 * where $watchers is an int:
369 * - if the page exists, number of users watching who have visited the page recently
370 * - if the page doesn't exist, number of users that have the page on their watchlist
371 * - 0 means there are no visiting watchers or their number is below the minimumWatchers
372 * option (if passed).
374 public function countVisitingWatchersMultiple(
375 array $targetsWithVisitThresholds,
376 $minimumWatchers = null
378 $dbr = $this->getConnection( DB_SLAVE
);
380 $conds = $this->getVisitingWatchersCondition( $dbr, $targetsWithVisitThresholds );
382 $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
383 if ( $minimumWatchers !== null ) {
384 $dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$minimumWatchers;
388 [ 'wl_namespace', 'wl_title', 'watchers' => 'COUNT(*)' ],
394 $this->reuseConnection( $dbr );
397 foreach ( $targetsWithVisitThresholds as list( $target ) ) {
398 /* @var LinkTarget $target */
399 $watcherCounts[$target->getNamespace()][$target->getDBkey()] = 0;
402 foreach ( $res as $row ) {
403 $watcherCounts[$row->wl_namespace
][$row->wl_title
] = (int)$row->watchers
;
406 return $watcherCounts;
410 * Generates condition for the query used in a batch count visiting watchers.
412 * @param IDatabase $db
413 * @param array $targetsWithVisitThresholds array of pairs (LinkTarget, last visit threshold)
416 private function getVisitingWatchersCondition(
418 array $targetsWithVisitThresholds
420 $missingTargets = [];
421 $namespaceConds = [];
422 foreach ( $targetsWithVisitThresholds as list( $target, $threshold ) ) {
423 if ( $threshold === null ) {
424 $missingTargets[] = $target;
427 /* @var LinkTarget $target */
428 $namespaceConds[$target->getNamespace()][] = $db->makeList( [
429 'wl_title = ' . $db->addQuotes( $target->getDBkey() ),
431 'wl_notificationtimestamp >= ' . $db->addQuotes( $db->timestamp( $threshold ) ),
432 'wl_notificationtimestamp IS NULL'
438 foreach ( $namespaceConds as $namespace => $pageConds ) {
439 $conds[] = $db->makeList( [
440 'wl_namespace = ' . $namespace,
441 '(' . $db->makeList( $pageConds, LIST_OR
) . ')'
445 if ( $missingTargets ) {
446 $lb = new LinkBatch( $missingTargets );
447 $conds[] = $lb->constructSet( 'wl', $db );
450 return $db->makeList( $conds, LIST_OR
);
454 * Get an item (may be cached)
457 * @param LinkTarget $target
459 * @return WatchedItem|false
461 public function getWatchedItem( User
$user, LinkTarget
$target ) {
462 if ( $user->isAnon() ) {
466 $cached = $this->getCached( $user, $target );
468 $this->stats
->increment( 'WatchedItemStore.getWatchedItem.cached' );
471 $this->stats
->increment( 'WatchedItemStore.getWatchedItem.load' );
472 return $this->loadWatchedItem( $user, $target );
476 * Loads an item from the db
479 * @param LinkTarget $target
481 * @return WatchedItem|false
483 public function loadWatchedItem( User
$user, LinkTarget
$target ) {
484 // Only loggedin user can have a watchlist
485 if ( $user->isAnon() ) {
489 $dbr = $this->getConnection( DB_SLAVE
);
490 $row = $dbr->selectRow(
492 'wl_notificationtimestamp',
493 $this->dbCond( $user, $target ),
496 $this->reuseConnection( $dbr );
502 $item = new WatchedItem(
505 $row->wl_notificationtimestamp
507 $this->cache( $item );
514 * @param array $options Allowed keys:
515 * 'forWrite' => bool defaults to false
516 * 'sort' => string optional sorting by namespace ID and title
517 * one of the self::SORT_* constants
519 * @return WatchedItem[]
521 public function getWatchedItemsForUser( User
$user, array $options = [] ) {
522 $options +
= [ 'forWrite' => false ];
525 if ( array_key_exists( 'sort', $options ) ) {
527 ( in_array( $options['sort'], [ self
::SORT_ASC
, self
::SORT_DESC
] ) ),
528 '$options[\'sort\']',
529 'must be SORT_ASC or SORT_DESC'
531 $dbOptions['ORDER BY'] = [
532 "wl_namespace {$options['sort']}",
533 "wl_title {$options['sort']}"
536 $db = $this->getConnection( $options['forWrite'] ? DB_MASTER
: DB_SLAVE
);
540 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
541 [ 'wl_user' => $user->getId() ],
545 $this->reuseConnection( $db );
548 foreach ( $res as $row ) {
549 // todo these could all be cached at some point?
550 $watchedItems[] = new WatchedItem(
552 new TitleValue( (int)$row->wl_namespace
, $row->wl_title
),
553 $row->wl_notificationtimestamp
557 return $watchedItems;
561 * Must be called separately for Subject & Talk namespaces
564 * @param LinkTarget $target
568 public function isWatched( User
$user, LinkTarget
$target ) {
569 return (bool)$this->getWatchedItem( $user, $target );
574 * @param LinkTarget[] $targets
576 * @return array multi-dimensional like $return[$namespaceId][$titleString] = $timestamp,
577 * where $timestamp is:
578 * - string|null value of wl_notificationtimestamp,
579 * - false if $target is not watched by $user.
581 public function getNotificationTimestampsBatch( User
$user, array $targets ) {
583 foreach ( $targets as $target ) {
584 $timestamps[$target->getNamespace()][$target->getDBkey()] = false;
587 if ( $user->isAnon() ) {
592 foreach ( $targets as $target ) {
593 $cachedItem = $this->getCached( $user, $target );
595 $timestamps[$target->getNamespace()][$target->getDBkey()] =
596 $cachedItem->getNotificationTimestamp();
598 $targetsToLoad[] = $target;
602 if ( !$targetsToLoad ) {
606 $dbr = $this->getConnection( DB_SLAVE
);
608 $lb = new LinkBatch( $targetsToLoad );
611 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
613 $lb->constructSet( 'wl', $dbr ),
614 'wl_user' => $user->getId(),
618 $this->reuseConnection( $dbr );
620 foreach ( $res as $row ) {
621 $timestamps[(int)$row->wl_namespace
][$row->wl_title
] = $row->wl_notificationtimestamp
;
628 * Must be called separately for Subject & Talk namespaces
631 * @param LinkTarget $target
633 public function addWatch( User
$user, LinkTarget
$target ) {
634 $this->addWatchBatchForUser( $user, [ $target ] );
639 * @param LinkTarget[] $targets
641 * @return bool success
643 public function addWatchBatchForUser( User
$user, array $targets ) {
644 if ( $this->loadBalancer
->getReadOnlyReason() !== false ) {
647 // Only loggedin user can have a watchlist
648 if ( $user->isAnon() ) {
657 foreach ( $targets as $target ) {
659 'wl_user' => $user->getId(),
660 'wl_namespace' => $target->getNamespace(),
661 'wl_title' => $target->getDBkey(),
662 'wl_notificationtimestamp' => null,
664 $this->uncache( $user, $target );
667 $dbw = $this->getConnection( DB_MASTER
);
668 foreach ( array_chunk( $rows, 100 ) as $toInsert ) {
669 // Use INSERT IGNORE to avoid overwriting the notification timestamp
670 // if there's already an entry for this page
671 $dbw->insert( 'watchlist', $toInsert, __METHOD__
, 'IGNORE' );
673 $this->reuseConnection( $dbw );
679 * Removes the an entry for the User watching the LinkTarget
680 * Must be called separately for Subject & Talk namespaces
683 * @param LinkTarget $target
685 * @return bool success
686 * @throws DBUnexpectedError
687 * @throws MWException
689 public function removeWatch( User
$user, LinkTarget
$target ) {
690 // Only logged in user can have a watchlist
691 if ( $this->loadBalancer
->getReadOnlyReason() !== false ||
$user->isAnon() ) {
695 $this->uncache( $user, $target );
697 $dbw = $this->getConnection( DB_MASTER
);
698 $dbw->delete( 'watchlist',
700 'wl_user' => $user->getId(),
701 'wl_namespace' => $target->getNamespace(),
702 'wl_title' => $target->getDBkey(),
705 $success = (bool)$dbw->affectedRows();
706 $this->reuseConnection( $dbw );
712 * @param User $editor The editor that triggered the update. Their notification
713 * timestamp will not be updated(they have already seen it)
714 * @param LinkTarget $target The target to update timestamps for
715 * @param string $timestamp Set the update timestamp to this value
717 * @return int[] Array of user IDs the timestamp has been updated for
719 public function updateNotificationTimestamp( User
$editor, LinkTarget
$target, $timestamp ) {
720 $dbw = $this->getConnection( DB_MASTER
);
721 $res = $dbw->select( [ 'watchlist' ],
724 'wl_user != ' . intval( $editor->getId() ),
725 'wl_namespace' => $target->getNamespace(),
726 'wl_title' => $target->getDBkey(),
727 'wl_notificationtimestamp IS NULL',
732 foreach ( $res as $row ) {
733 $watchers[] = intval( $row->wl_user
);
737 // Update wl_notificationtimestamp for all watching users except the editor
739 $dbw->onTransactionIdle(
740 function () use ( $dbw, $timestamp, $watchers, $target, $fname ) {
741 $dbw->update( 'watchlist',
743 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
745 'wl_user' => $watchers,
746 'wl_namespace' => $target->getNamespace(),
747 'wl_title' => $target->getDBkey(),
750 $this->uncacheLinkTarget( $target );
755 $this->reuseConnection( $dbw );
761 * Reset the notification timestamp of this entry
764 * @param Title $title
765 * @param string $force Whether to force the write query to be executed even if the
766 * page is not watched or the notification timestamp is already NULL.
767 * 'force' in order to force
768 * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed.
770 * @return bool success
772 public function resetNotificationTimestamp( User
$user, Title
$title, $force = '', $oldid = 0 ) {
773 // Only loggedin user can have a watchlist
774 if ( $this->loadBalancer
->getReadOnlyReason() !== false ||
$user->isAnon() ) {
779 if ( $force != 'force' ) {
780 $item = $this->loadWatchedItem( $user, $title );
781 if ( !$item ||
$item->getNotificationTimestamp() === null ) {
786 // If the page is watched by the user (or may be watched), update the timestamp
787 $job = new ActivityUpdateJob(
790 'type' => 'updateWatchlistNotification',
791 'userid' => $user->getId(),
792 'notifTime' => $this->getNotificationTimestamp( $user, $title, $item, $force, $oldid ),
797 // Try to run this post-send
798 // Calls DeferredUpdates::addCallableUpdate in normal operation
800 $this->deferredUpdatesAddCallableUpdateCallback
,
801 function() use ( $job ) {
806 $this->uncache( $user, $title );
811 private function getNotificationTimestamp( User
$user, Title
$title, $item, $force, $oldid ) {
813 // No oldid given, assuming latest revision; clear the timestamp.
817 if ( !$title->getNextRevisionID( $oldid ) ) {
818 // Oldid given and is the latest revision for this title; clear the timestamp.
822 if ( $item === null ) {
823 $item = $this->loadWatchedItem( $user, $title );
827 // This can only happen if $force is enabled.
831 // Oldid given and isn't the latest; update the timestamp.
832 // This will result in no further notification emails being sent!
833 // Calls Revision::getTimestampFromId in normal operation
834 $notificationTimestamp = call_user_func(
835 $this->revisionGetTimestampFromIdCallback
,
840 // We need to go one second to the future because of various strict comparisons
841 // throughout the codebase
842 $ts = new MWTimestamp( $notificationTimestamp );
843 $ts->timestamp
->add( new DateInterval( 'PT1S' ) );
844 $notificationTimestamp = $ts->getTimestamp( TS_MW
);
846 if ( $notificationTimestamp < $item->getNotificationTimestamp() ) {
847 if ( $force != 'force' ) {
850 // This is a little silly…
851 return $item->getNotificationTimestamp();
855 return $notificationTimestamp;
860 * @param int $unreadLimit
862 * @return int|bool The number of unread notifications
863 * true if greater than or equal to $unreadLimit
865 public function countUnreadNotifications( User
$user, $unreadLimit = null ) {
867 if ( $unreadLimit !== null ) {
868 $unreadLimit = (int)$unreadLimit;
869 $queryOptions['LIMIT'] = $unreadLimit;
872 $dbr = $this->getConnection( DB_SLAVE
);
873 $rowCount = $dbr->selectRowCount(
877 'wl_user' => $user->getId(),
878 'wl_notificationtimestamp IS NOT NULL',
883 $this->reuseConnection( $dbr );
885 if ( !isset( $unreadLimit ) ) {
889 if ( $rowCount >= $unreadLimit ) {
897 * Check if the given title already is watched by the user, and if so
898 * add a watch for the new title.
900 * To be used for page renames and such.
902 * @param LinkTarget $oldTarget
903 * @param LinkTarget $newTarget
905 public function duplicateAllAssociatedEntries( LinkTarget
$oldTarget, LinkTarget
$newTarget ) {
906 if ( !$oldTarget instanceof Title
) {
907 $oldTarget = Title
::newFromLinkTarget( $oldTarget );
909 if ( !$newTarget instanceof Title
) {
910 $newTarget = Title
::newFromLinkTarget( $newTarget );
913 $this->duplicateEntry( $oldTarget->getSubjectPage(), $newTarget->getSubjectPage() );
914 $this->duplicateEntry( $oldTarget->getTalkPage(), $newTarget->getTalkPage() );
918 * Check if the given title already is watched by the user, and if so
919 * add a watch for the new title.
921 * To be used for page renames and such.
922 * This must be called separately for Subject and Talk pages
924 * @param LinkTarget $oldTarget
925 * @param LinkTarget $newTarget
927 public function duplicateEntry( LinkTarget
$oldTarget, LinkTarget
$newTarget ) {
928 $dbw = $this->getConnection( DB_MASTER
);
930 $result = $dbw->select(
932 [ 'wl_user', 'wl_notificationtimestamp' ],
934 'wl_namespace' => $oldTarget->getNamespace(),
935 'wl_title' => $oldTarget->getDBkey(),
941 $newNamespace = $newTarget->getNamespace();
942 $newDBkey = $newTarget->getDBkey();
944 # Construct array to replace into the watchlist
946 foreach ( $result as $row ) {
948 'wl_user' => $row->wl_user
,
949 'wl_namespace' => $newNamespace,
950 'wl_title' => $newDBkey,
951 'wl_notificationtimestamp' => $row->wl_notificationtimestamp
,
955 if ( !empty( $values ) ) {
957 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
958 # some other DBMSes, mostly due to poor simulation by us
961 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
967 $this->reuseConnection( $dbw );