Merge "Title::getTalkPage(): Restore behavior of interwiki-prefixed & fragment-only...
[lhc/web/wiklou.git] / includes / jobqueue / utils / PurgeJobUtils.php
index d76d866..1e40eb4 100644 (file)
@@ -20,6 +20,7 @@
  *
  * @file
  */
+use Wikimedia\Rdbms\IDatabase;
 use MediaWiki\MediaWikiServices;
 
 class PurgeJobUtils {
@@ -35,9 +36,12 @@ class PurgeJobUtils {
                if ( $dbkeys === [] ) {
                        return;
                }
+               $fname = __METHOD__;
 
-               $dbw->onTransactionIdle(
-                       function () use ( $dbw, $namespace, $dbkeys ) {
+               DeferredUpdates::addUpdate( new AutoCommitUpdate(
+                       $dbw,
+                       __METHOD__,
+                       function () use ( $dbw, $namespace, $dbkeys, $fname ) {
                                $services = MediaWikiServices::getInstance();
                                $lbFactory = $services->getDBLoadBalancerFactory();
                                // Determine which pages need to be updated.
@@ -52,7 +56,7 @@ class PurgeJobUtils {
                                                'page_title' => $dbkeys,
                                                'page_touched < ' . $dbw->addQuotes( $now )
                                        ],
-                                       __METHOD__
+                                       $fname
                                );
 
                                if ( !$ids ) {
@@ -60,8 +64,9 @@ class PurgeJobUtils {
                                }
 
                                $batchSize = $services->getMainConfig()->get( 'UpdateRowsPerQuery' );
-                               $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
-                               foreach ( array_chunk( $ids, $batchSize ) as $idBatch ) {
+                               $ticket = $lbFactory->getEmptyTransactionTicket( $fname );
+                               $idBatches = array_chunk( $ids, $batchSize );
+                               foreach ( $idBatches as $idBatch ) {
                                        $dbw->update(
                                                'page',
                                                [ 'page_touched' => $now ],
@@ -69,12 +74,13 @@ class PurgeJobUtils {
                                                        'page_id' => $idBatch,
                                                        'page_touched < ' . $dbw->addQuotes( $now ) // handle races
                                                ],
-                                               __METHOD__
+                                               $fname
                                        );
-                                       $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
+                                       if ( count( $idBatches ) > 1 ) {
+                                               $lbFactory->commitAndWaitForReplication( $fname, $ticket );
+                                       }
                                }
-                       },
-                       __METHOD__
-               );
+                       }
+               ) );
        }
 }