From 14b888c515b02115aa412696af8e3f85e7beade2 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Mon, 23 May 2016 20:49:21 +0200 Subject: [PATCH] Batch updateNotificationTimestamp() UPDATE queries (without wl_id) The new primary key is not usable in production (T130067), so batch the query using the old where condition. Some code ideas from I3dbe1de4cf39499728a2077a71157d4bcc203e44 Bug: T134613 Change-Id: Ic12926a5166f7578a1136c7944d883c2fe1f3b3a --- includes/WatchedItemStore.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index f0619d69f5..6486955fc4 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -744,15 +744,24 @@ class WatchedItemStore implements StatsdAwareInterface { $fname = __METHOD__; $dbw->onTransactionIdle( function () use ( $dbw, $timestamp, $watchers, $target, $fname ) { - $dbw->update( 'watchlist', - [ /* SET */ - 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp ) - ], [ /* WHERE */ - 'wl_user' => $watchers, - 'wl_namespace' => $target->getNamespace(), - 'wl_title' => $target->getDBkey(), - ], $fname - ); + global $wgUpdateRowsPerQuery; + + $watchersChunks = array_chunk( $watchers, $wgUpdateRowsPerQuery ); + foreach ( $watchersChunks as $watchersChunk ) { + $dbw->update( 'watchlist', + [ /* SET */ + 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp ) + ], [ /* WHERE - TODO Use wl_id T130067 */ + 'wl_user' => $watchersChunk, + 'wl_namespace' => $target->getNamespace(), + 'wl_title' => $target->getDBkey(), + ], $fname + ); + if ( count( $watchersChunks ) > 1 ) { + $dbw->commit( __METHOD__, 'flush' ); + wfGetLBFactory()->waitForReplication( [ 'wiki' => $dbw->getWikiID() ] ); + } + } $this->uncacheLinkTarget( $target ); } ); -- 2.20.1