3 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface
;
4 use Wikimedia\Assert\Assert
;
7 * Storage layer class for WatchedItems.
8 * Database interaction.
14 class WatchedItemStore
implements StatsdAwareInterface
{
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
61 public function __construct(
62 LoadBalancer
$loadBalancer,
65 $this->loadBalancer
= $loadBalancer;
66 $this->cache
= $cache;
67 $this->stats
= new NullStatsdDataFactory();
68 $this->deferredUpdatesAddCallableUpdateCallback
= [ 'DeferredUpdates', 'addCallableUpdate' ];
69 $this->revisionGetTimestampFromIdCallback
= [ 'Revision', 'getTimestampFromId' ];
72 public function setStatsdDataFactory( StatsdDataFactoryInterface
$stats ) {
73 $this->stats
= $stats;
77 * Overrides the DeferredUpdates::addCallableUpdate callback
78 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
80 * @param callable $callback
82 * @see DeferredUpdates::addCallableUpdate for callback signiture
84 * @return ScopedCallback to reset the overridden value
87 public function overrideDeferredUpdatesAddCallableUpdateCallback( $callback ) {
88 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
89 throw new MWException(
90 'Cannot override DeferredUpdates::addCallableUpdate callback in operation.'
93 Assert
::parameterType( 'callable', $callback, '$callback' );
95 $previousValue = $this->deferredUpdatesAddCallableUpdateCallback
;
96 $this->deferredUpdatesAddCallableUpdateCallback
= $callback;
97 return new ScopedCallback( function() use ( $previousValue ) {
98 $this->deferredUpdatesAddCallableUpdateCallback
= $previousValue;
103 * Overrides the Revision::getTimestampFromId callback
104 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
106 * @param callable $callback
107 * @see Revision::getTimestampFromId for callback signiture
109 * @return ScopedCallback to reset the overridden value
110 * @throws MWException
112 public function overrideRevisionGetTimestampFromIdCallback( $callback ) {
113 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
114 throw new MWException(
115 'Cannot override Revision::getTimestampFromId callback in operation.'
118 Assert
::parameterType( 'callable', $callback, '$callback' );
120 $previousValue = $this->revisionGetTimestampFromIdCallback
;
121 $this->revisionGetTimestampFromIdCallback
= $callback;
122 return new ScopedCallback( function() use ( $previousValue ) {
123 $this->revisionGetTimestampFromIdCallback
= $previousValue;
128 * Overrides the default instance of this class
129 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
131 * If this method is used it MUST also be called with null after a test to ensure a new
132 * default instance is created next time getDefaultInstance is called.
134 * @param WatchedItemStore|null $store
136 * @return ScopedCallback to reset the overridden value
137 * @throws MWException
139 public static function overrideDefaultInstance( WatchedItemStore
$store = null ) {
140 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
141 throw new MWException(
142 'Cannot override ' . __CLASS__
. 'default instance in operation.'
146 $previousValue = self
::$instance;
147 self
::$instance = $store;
148 return new ScopedCallback( function() use ( $previousValue ) {
149 self
::$instance = $previousValue;
156 public static function getDefaultInstance() {
157 if ( !self
::$instance ) {
158 self
::$instance = new self(
160 new HashBagOStuff( [ 'maxKeys' => 100 ] )
162 self
::$instance->setStatsdDataFactory( RequestContext
::getMain()->getStats() );
164 return self
::$instance;
167 private function getCacheKey( User
$user, LinkTarget
$target ) {
168 return $this->cache
->makeKey(
169 (string)$target->getNamespace(),
171 (string)$user->getId()
175 private function cache( WatchedItem
$item ) {
176 $user = $item->getUser();
177 $target = $item->getLinkTarget();
178 $key = $this->getCacheKey( $user, $target );
179 $this->cache
->set( $key, $item );
180 $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()][$user->getId()] = $key;
181 $this->stats
->increment( 'WatchedItemStore.cache' );
184 private function uncache( User
$user, LinkTarget
$target ) {
185 $this->cache
->delete( $this->getCacheKey( $user, $target ) );
186 unset( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()][$user->getId()] );
187 $this->stats
->increment( 'WatchedItemStore.uncache' );
190 private function uncacheLinkTarget( LinkTarget
$target ) {
191 if ( !isset( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()] ) ) {
194 $this->stats
->increment( 'WatchedItemStore.uncacheLinkTarget' );
195 foreach ( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()] as $key ) {
196 $this->stats
->increment( 'WatchedItemStore.uncacheLinkTarget.items' );
197 $this->cache
->delete( $key );
203 * @param LinkTarget $target
205 * @return WatchedItem|null
207 private function getCached( User
$user, LinkTarget
$target ) {
208 return $this->cache
->get( $this->getCacheKey( $user, $target ) );
212 * Return an array of conditions to select or update the appropriate database
216 * @param LinkTarget $target
220 private function dbCond( User
$user, LinkTarget
$target ) {
222 'wl_user' => $user->getId(),
223 'wl_namespace' => $target->getNamespace(),
224 'wl_title' => $target->getDBkey(),
229 * @param int $slaveOrMaster DB_MASTER or DB_SLAVE
231 * @return DatabaseBase
232 * @throws MWException
234 private function getConnection( $slaveOrMaster ) {
235 return $this->loadBalancer
->getConnection( $slaveOrMaster, [ 'watchlist' ] );
239 * @param DatabaseBase $connection
241 * @throws MWException
243 private function reuseConnection( $connection ) {
244 $this->loadBalancer
->reuseConnection( $connection );
248 * Count the number of individual items that are watched by the user.
249 * If a subject and corresponding talk page are watched this will return 2.
255 public function countWatchedItems( User
$user ) {
256 $dbr = $this->getConnection( DB_SLAVE
);
257 $return = (int)$dbr->selectField(
261 'wl_user' => $user->getId()
265 $this->reuseConnection( $dbr );
271 * @param LinkTarget $target
275 public function countWatchers( LinkTarget
$target ) {
276 $dbr = $this->getConnection( DB_SLAVE
);
277 $return = (int)$dbr->selectField(
281 'wl_namespace' => $target->getNamespace(),
282 'wl_title' => $target->getDBkey(),
286 $this->reuseConnection( $dbr );
292 * Number of page watchers who also visited a "recent" edit
294 * @param LinkTarget $target
295 * @param mixed $threshold timestamp accepted by wfTimestamp
298 * @throws DBUnexpectedError
299 * @throws MWException
301 public function countVisitingWatchers( LinkTarget
$target, $threshold ) {
302 $dbr = $this->getConnection( DB_SLAVE
);
303 $visitingWatchers = (int)$dbr->selectField(
307 'wl_namespace' => $target->getNamespace(),
308 'wl_title' => $target->getDBkey(),
309 'wl_notificationtimestamp >= ' .
310 $dbr->addQuotes( $dbr->timestamp( $threshold ) ) .
311 ' OR wl_notificationtimestamp IS NULL'
315 $this->reuseConnection( $dbr );
317 return $visitingWatchers;
321 * @param LinkTarget[] $targets
322 * @param array $options Allowed keys:
323 * 'minimumWatchers' => int
325 * @return array multi dimensional like $return[$namespaceId][$titleString] = int $watchers
326 * All targets will be present in the result. 0 either means no watchers or the number
327 * of watchers was below the minimumWatchers option if passed.
329 public function countWatchersMultiple( array $targets, array $options = [] ) {
330 $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
332 $dbr = $this->getConnection( DB_SLAVE
);
334 if ( array_key_exists( 'minimumWatchers', $options ) ) {
335 $dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$options['minimumWatchers'];
338 $lb = new LinkBatch( $targets );
341 [ 'wl_title', 'wl_namespace', 'watchers' => 'COUNT(*)' ],
342 [ $lb->constructSet( 'wl', $dbr ) ],
347 $this->reuseConnection( $dbr );
350 foreach ( $targets as $linkTarget ) {
351 $watchCounts[$linkTarget->getNamespace()][$linkTarget->getDBkey()] = 0;
354 foreach ( $res as $row ) {
355 $watchCounts[$row->wl_namespace
][$row->wl_title
] = (int)$row->watchers
;
362 * Number of watchers of each page who have visited recent edits to that page
364 * @param array $targetsWithVisitThresholds array of pairs (LinkTarget $target, mixed $threshold),
366 * - a timestamp of the recent edit if $target exists (format accepted by wfTimestamp)
367 * - null if $target doesn't exist
368 * @param int|null $minimumWatchers
369 * @return array multi-dimensional like $return[$namespaceId][$titleString] = $watchers,
370 * where $watchers is an int:
371 * - if the page exists, number of users watching who have visited the page recently
372 * - if the page doesn't exist, number of users that have the page on their watchlist
373 * - 0 means there are no visiting watchers or their number is below the minimumWatchers
374 * option (if passed).
376 public function countVisitingWatchersMultiple(
377 array $targetsWithVisitThresholds,
378 $minimumWatchers = null
380 $dbr = $this->getConnection( DB_SLAVE
);
382 $conds = $this->getVisitingWatchersCondition( $dbr, $targetsWithVisitThresholds );
384 $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
385 if ( $minimumWatchers !== null ) {
386 $dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$minimumWatchers;
390 [ 'wl_namespace', 'wl_title', 'watchers' => 'COUNT(*)' ],
396 $this->reuseConnection( $dbr );
399 foreach ( $targetsWithVisitThresholds as list( $target ) ) {
400 /* @var LinkTarget $target */
401 $watcherCounts[$target->getNamespace()][$target->getDBkey()] = 0;
404 foreach ( $res as $row ) {
405 $watcherCounts[$row->wl_namespace
][$row->wl_title
] = (int)$row->watchers
;
408 return $watcherCounts;
412 * Generates condition for the query used in a batch count visiting watchers.
414 * @param IDatabase $db
415 * @param array $targetsWithVisitThresholds array of pairs (LinkTarget, last visit threshold)
418 private function getVisitingWatchersCondition(
420 array $targetsWithVisitThresholds
422 $missingTargets = [];
423 $namespaceConds = [];
424 foreach ( $targetsWithVisitThresholds as list( $target, $threshold ) ) {
425 if ( $threshold === null ) {
426 $missingTargets[] = $target;
429 /* @var LinkTarget $target */
430 $namespaceConds[$target->getNamespace()][] = $db->makeList( [
431 'wl_title = ' . $db->addQuotes( $target->getDBkey() ),
433 'wl_notificationtimestamp >= ' . $db->addQuotes( $db->timestamp( $threshold ) ),
434 'wl_notificationtimestamp IS NULL'
440 foreach ( $namespaceConds as $namespace => $pageConds ) {
441 $conds[] = $db->makeList( [
442 'wl_namespace = ' . $namespace,
443 '(' . $db->makeList( $pageConds, LIST_OR
) . ')'
447 if ( $missingTargets ) {
448 $lb = new LinkBatch( $missingTargets );
449 $conds[] = $lb->constructSet( 'wl', $db );
452 return $db->makeList( $conds, LIST_OR
);
456 * Get an item (may be cached)
459 * @param LinkTarget $target
461 * @return WatchedItem|false
463 public function getWatchedItem( User
$user, LinkTarget
$target ) {
464 if ( $user->isAnon() ) {
468 $cached = $this->getCached( $user, $target );
470 $this->stats
->increment( 'WatchedItemStore.getWatchedItem.cached' );
473 $this->stats
->increment( 'WatchedItemStore.getWatchedItem.load' );
474 return $this->loadWatchedItem( $user, $target );
478 * Loads an item from the db
481 * @param LinkTarget $target
483 * @return WatchedItem|false
485 public function loadWatchedItem( User
$user, LinkTarget
$target ) {
486 // Only loggedin user can have a watchlist
487 if ( $user->isAnon() ) {
491 $dbr = $this->getConnection( DB_SLAVE
);
492 $row = $dbr->selectRow(
494 'wl_notificationtimestamp',
495 $this->dbCond( $user, $target ),
498 $this->reuseConnection( $dbr );
504 $item = new WatchedItem(
507 $row->wl_notificationtimestamp
509 $this->cache( $item );
516 * @param array $options Allowed keys:
517 * 'forWrite' => bool defaults to false
518 * 'sort' => string optional sorting by namespace ID and title
519 * one of the self::SORT_* constants
521 * @return WatchedItem[]
523 public function getWatchedItemsForUser( User
$user, array $options = [] ) {
524 $options +
= [ 'forWrite' => false ];
527 if ( array_key_exists( 'sort', $options ) ) {
529 ( in_array( $options['sort'], [ self
::SORT_ASC
, self
::SORT_DESC
] ) ),
530 '$options[\'sort\']',
531 'must be SORT_ASC or SORT_DESC'
533 $dbOptions['ORDER BY'] = [
534 "wl_namespace {$options['sort']}",
535 "wl_title {$options['sort']}"
538 $db = $this->getConnection( $options['forWrite'] ? DB_MASTER
: DB_SLAVE
);
542 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
543 [ 'wl_user' => $user->getId() ],
547 $this->reuseConnection( $db );
550 foreach ( $res as $row ) {
551 // todo these could all be cached at some point?
552 $watchedItems[] = new WatchedItem(
554 new TitleValue( (int)$row->wl_namespace
, $row->wl_title
),
555 $row->wl_notificationtimestamp
559 return $watchedItems;
563 * Must be called separately for Subject & Talk namespaces
566 * @param LinkTarget $target
570 public function isWatched( User
$user, LinkTarget
$target ) {
571 return (bool)$this->getWatchedItem( $user, $target );
576 * @param LinkTarget[] $targets
578 * @return array multi-dimensional like $return[$namespaceId][$titleString] = $timestamp,
579 * where $timestamp is:
580 * - string|null value of wl_notificationtimestamp,
581 * - false if $target is not watched by $user.
583 public function getNotificationTimestampsBatch( User
$user, array $targets ) {
585 foreach ( $targets as $target ) {
586 $timestamps[$target->getNamespace()][$target->getDBkey()] = false;
589 if ( $user->isAnon() ) {
594 foreach ( $targets as $target ) {
595 $cachedItem = $this->getCached( $user, $target );
597 $timestamps[$target->getNamespace()][$target->getDBkey()] =
598 $cachedItem->getNotificationTimestamp();
600 $targetsToLoad[] = $target;
604 if ( !$targetsToLoad ) {
608 $dbr = $this->getConnection( DB_SLAVE
);
610 $lb = new LinkBatch( $targetsToLoad );
613 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
615 $lb->constructSet( 'wl', $dbr ),
616 'wl_user' => $user->getId(),
620 $this->reuseConnection( $dbr );
622 foreach ( $res as $row ) {
623 $timestamps[(int)$row->wl_namespace
][$row->wl_title
] = $row->wl_notificationtimestamp
;
630 * Must be called separately for Subject & Talk namespaces
633 * @param LinkTarget $target
635 public function addWatch( User
$user, LinkTarget
$target ) {
636 $this->addWatchBatchForUser( $user, [ $target ] );
641 * @param LinkTarget[] $targets
643 * @return bool success
645 public function addWatchBatchForUser( User
$user, array $targets ) {
646 if ( $this->loadBalancer
->getReadOnlyReason() !== false ) {
649 // Only loggedin user can have a watchlist
650 if ( $user->isAnon() ) {
659 foreach ( $targets as $target ) {
661 'wl_user' => $user->getId(),
662 'wl_namespace' => $target->getNamespace(),
663 'wl_title' => $target->getDBkey(),
664 'wl_notificationtimestamp' => null,
666 $this->uncache( $user, $target );
669 $dbw = $this->getConnection( DB_MASTER
);
670 foreach ( array_chunk( $rows, 100 ) as $toInsert ) {
671 // Use INSERT IGNORE to avoid overwriting the notification timestamp
672 // if there's already an entry for this page
673 $dbw->insert( 'watchlist', $toInsert, __METHOD__
, 'IGNORE' );
675 $this->reuseConnection( $dbw );
681 * Removes the an entry for the User watching the LinkTarget
682 * Must be called separately for Subject & Talk namespaces
685 * @param LinkTarget $target
687 * @return bool success
688 * @throws DBUnexpectedError
689 * @throws MWException
691 public function removeWatch( User
$user, LinkTarget
$target ) {
692 // Only logged in user can have a watchlist
693 if ( $this->loadBalancer
->getReadOnlyReason() !== false ||
$user->isAnon() ) {
697 $this->uncache( $user, $target );
699 $dbw = $this->getConnection( DB_MASTER
);
700 $dbw->delete( 'watchlist',
702 'wl_user' => $user->getId(),
703 'wl_namespace' => $target->getNamespace(),
704 'wl_title' => $target->getDBkey(),
707 $success = (bool)$dbw->affectedRows();
708 $this->reuseConnection( $dbw );
714 * @param User $editor The editor that triggered the update. Their notification
715 * timestamp will not be updated(they have already seen it)
716 * @param LinkTarget $target The target to update timestamps for
717 * @param string $timestamp Set the update timestamp to this value
719 * @return int[] Array of user IDs the timestamp has been updated for
721 public function updateNotificationTimestamp( User
$editor, LinkTarget
$target, $timestamp ) {
722 $dbw = $this->getConnection( DB_MASTER
);
723 $res = $dbw->select( [ 'watchlist' ],
726 'wl_user != ' . intval( $editor->getId() ),
727 'wl_namespace' => $target->getNamespace(),
728 'wl_title' => $target->getDBkey(),
729 'wl_notificationtimestamp IS NULL',
734 foreach ( $res as $row ) {
735 $watchers[] = intval( $row->wl_user
);
739 // Update wl_notificationtimestamp for all watching users except the editor
741 $dbw->onTransactionIdle(
742 function () use ( $dbw, $timestamp, $watchers, $target, $fname ) {
743 $dbw->update( 'watchlist',
745 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
747 'wl_user' => $watchers,
748 'wl_namespace' => $target->getNamespace(),
749 'wl_title' => $target->getDBkey(),
752 $this->uncacheLinkTarget( $target );
757 $this->reuseConnection( $dbw );
763 * Reset the notification timestamp of this entry
766 * @param Title $title
767 * @param string $force Whether to force the write query to be executed even if the
768 * page is not watched or the notification timestamp is already NULL.
769 * 'force' in order to force
770 * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed.
772 * @return bool success
774 public function resetNotificationTimestamp( User
$user, Title
$title, $force = '', $oldid = 0 ) {
775 // Only loggedin user can have a watchlist
776 if ( $this->loadBalancer
->getReadOnlyReason() !== false ||
$user->isAnon() ) {
781 if ( $force != 'force' ) {
782 $item = $this->loadWatchedItem( $user, $title );
783 if ( !$item ||
$item->getNotificationTimestamp() === null ) {
788 // If the page is watched by the user (or may be watched), update the timestamp
789 $job = new ActivityUpdateJob(
792 'type' => 'updateWatchlistNotification',
793 'userid' => $user->getId(),
794 'notifTime' => $this->getNotificationTimestamp( $user, $title, $item, $force, $oldid ),
799 // Try to run this post-send
800 // Calls DeferredUpdates::addCallableUpdate in normal operation
802 $this->deferredUpdatesAddCallableUpdateCallback
,
803 function() use ( $job ) {
808 $this->uncache( $user, $title );
813 private function getNotificationTimestamp( User
$user, Title
$title, $item, $force, $oldid ) {
815 // No oldid given, assuming latest revision; clear the timestamp.
819 if ( !$title->getNextRevisionID( $oldid ) ) {
820 // Oldid given and is the latest revision for this title; clear the timestamp.
824 if ( $item === null ) {
825 $item = $this->loadWatchedItem( $user, $title );
829 // This can only happen if $force is enabled.
833 // Oldid given and isn't the latest; update the timestamp.
834 // This will result in no further notification emails being sent!
835 // Calls Revision::getTimestampFromId in normal operation
836 $notificationTimestamp = call_user_func(
837 $this->revisionGetTimestampFromIdCallback
,
842 // We need to go one second to the future because of various strict comparisons
843 // throughout the codebase
844 $ts = new MWTimestamp( $notificationTimestamp );
845 $ts->timestamp
->add( new DateInterval( 'PT1S' ) );
846 $notificationTimestamp = $ts->getTimestamp( TS_MW
);
848 if ( $notificationTimestamp < $item->getNotificationTimestamp() ) {
849 if ( $force != 'force' ) {
852 // This is a little silly…
853 return $item->getNotificationTimestamp();
857 return $notificationTimestamp;
862 * @param int $unreadLimit
864 * @return int|bool The number of unread notifications
865 * true if greater than or equal to $unreadLimit
867 public function countUnreadNotifications( User
$user, $unreadLimit = null ) {
869 if ( $unreadLimit !== null ) {
870 $unreadLimit = (int)$unreadLimit;
871 $queryOptions['LIMIT'] = $unreadLimit;
874 $dbr = $this->getConnection( DB_SLAVE
);
875 $rowCount = $dbr->selectRowCount(
879 'wl_user' => $user->getId(),
880 'wl_notificationtimestamp IS NOT NULL',
885 $this->reuseConnection( $dbr );
887 if ( !isset( $unreadLimit ) ) {
891 if ( $rowCount >= $unreadLimit ) {
899 * Check if the given title already is watched by the user, and if so
900 * add a watch for the new title.
902 * To be used for page renames and such.
904 * @param LinkTarget $oldTarget
905 * @param LinkTarget $newTarget
907 public function duplicateAllAssociatedEntries( LinkTarget
$oldTarget, LinkTarget
$newTarget ) {
908 $oldTarget = Title
::newFromLinkTarget( $oldTarget );
909 $newTarget = Title
::newFromLinkTarget( $newTarget );
911 $this->duplicateEntry( $oldTarget->getSubjectPage(), $newTarget->getSubjectPage() );
912 $this->duplicateEntry( $oldTarget->getTalkPage(), $newTarget->getTalkPage() );
916 * Check if the given title already is watched by the user, and if so
917 * add a watch for the new title.
919 * To be used for page renames and such.
920 * This must be called separately for Subject and Talk pages
922 * @param LinkTarget $oldTarget
923 * @param LinkTarget $newTarget
925 public function duplicateEntry( LinkTarget
$oldTarget, LinkTarget
$newTarget ) {
926 $dbw = $this->getConnection( DB_MASTER
);
928 $result = $dbw->select(
930 [ 'wl_user', 'wl_notificationtimestamp' ],
932 'wl_namespace' => $oldTarget->getNamespace(),
933 'wl_title' => $oldTarget->getDBkey(),
939 $newNamespace = $newTarget->getNamespace();
940 $newDBkey = $newTarget->getDBkey();
942 # Construct array to replace into the watchlist
944 foreach ( $result as $row ) {
946 'wl_user' => $row->wl_user
,
947 'wl_namespace' => $newNamespace,
948 'wl_title' => $newDBkey,
949 'wl_notificationtimestamp' => $row->wl_notificationtimestamp
,
953 if ( !empty( $values ) ) {
955 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
956 # some other DBMSes, mostly due to poor simulation by us
959 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
965 $this->reuseConnection( $dbw );