Batch updateNotificationTimestamp() UPDATE queries (without wl_id)
authorumherirrender <umherirrender_de.wp@web.de>
Mon, 23 May 2016 18:49:21 +0000 (20:49 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Mon, 23 May 2016 19:16:38 +0000 (21:16 +0200)
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

index f0619d6..6486955 100644 (file)
@@ -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 );
                                }
                        );