Limit DELETE in purgeExpiredRestrictions() and use primary key
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 17 May 2016 11:19:29 +0000 (04:19 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 19 May 2016 20:17:31 +0000 (13:17 -0700)
This should help reduce contention in some cases.
If too many rows are expired, subsequent updates will
clear them out.

Bug: T135470
Change-Id: Iada496d0db9b00e77037320d7c65124a8c8f68c0

includes/Title.php

index 25fbce3..3a5b62b 100644 (file)
@@ -2971,6 +2971,8 @@ class Title implements LinkTarget {
 
        /**
         * Purge expired restrictions from the page_restrictions table
+        *
+        * This will purge no more than $wgUpdateRowsPerQuery page_restrictions rows
         */
        static function purgeExpiredRestrictions() {
                if ( wfReadOnly() ) {
@@ -2981,11 +2983,24 @@ class Title implements LinkTarget {
                        wfGetDB( DB_MASTER ),
                        __METHOD__,
                        function ( IDatabase $dbw, $fname ) {
-                               $dbw->delete(
+                               $config = MediaWikiServices::getInstance()->getMainConfig();
+                               $ids = $dbw->selectFieldValues(
                                        'page_restrictions',
+                                       'pr_id',
                                        [ 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
-                                       $fname
+                                       $fname,
+                                       [ 'LIMIT' => $config->get( 'UpdateRowsPerQuery' ) ] // T135470
                                );
+                               if ( $ids ) {
+                                       $dbw->delete( 'page_restrictions', [ 'pr_id' => $ids ], $fname );
+                               }
+                       }
+               ) );
+
+               DeferredUpdates::addUpdate( new AtomicSectionUpdate(
+                       wfGetDB( DB_MASTER ),
+                       __METHOD__,
+                       function ( IDatabase $dbw, $fname ) {
                                $dbw->delete(
                                        'protected_titles',
                                        [ 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],