Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/242649

Change subject: Made LinksUpdate on edit use the job queue
......................................................................

Made LinksUpdate on edit use the job queue

* LinksUpdate is now an EnqueueableDataUpdate
  and can yeild a prioritzed refreshLinks job.
* DeferredUpdates::runUpdates() now takes an enqueue
  flag to try to use jobs. This is set in restInPeace().
  Updates that change many links will be less likely to
  increase lag, as the runners are more strict about that.
* Also made the LinksDeletionUpdate job enqueue happen
  post-send on page deletion for consistency

Bug: T95501
Change-Id: I8863caef9c8f03234699d33e4d47d2310a0c8446
---
M includes/MediaWiki.php
M includes/deferred/DeferredUpdates.php
M includes/deferred/LinksUpdate.php
M includes/page/WikiPage.php
4 files changed, 30 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/49/242649/1

diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index fbacb25..e355541 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -703,7 +703,7 @@
                
Profiler::instance()->getTransactionProfiler()->resetExpectations();
 
                // Do any deferred jobs
-               DeferredUpdates::doUpdates( 'commit' );
+               DeferredUpdates::doUpdates( 'commit', 'enqueue' );
 
                // Make sure any lazy jobs are pushed
                JobQueueGroup::pushLazyJobs();
diff --git a/includes/deferred/DeferredUpdates.php 
b/includes/deferred/DeferredUpdates.php
index cd0266f..aeba862 100644
--- a/includes/deferred/DeferredUpdates.php
+++ b/includes/deferred/DeferredUpdates.php
@@ -45,7 +45,7 @@
  */
 class DeferredUpdates {
        /**
-        * @var array Updates to be deferred until the end of the request.
+        * @var DeferrableUpdate[] Updates to be deferred until the end of the 
request.
         */
        private static $updates = array();
 
@@ -92,21 +92,27 @@
         * Do any deferred updates and clear the list
         *
         * @param string $commit Set to 'commit' to commit after every update to
+        * @param string $mode Use "enqueue" to use the job queue when possible 
[Default: run]
         *   prevent lock contention
         */
-       public static function doUpdates( $commit = '' ) {
+       public static function doUpdates( $commit = '', $mode = 'run' ) {
                $updates = self::$updates;
 
                while ( count( $updates ) ) {
                        self::clearPendingUpdates();
 
-                       /** @var DeferrableUpdate $update */
                        foreach ( $updates as $update ) {
                                try {
-                                       $update->doUpdate();
-
-                                       if ( $commit === 'commit' ) {
-                                               
wfGetLBFactory()->commitMasterChanges();
+                                       // Enqueue jobs if requested and 
possible
+                                       if ( $mode === 'enqueue' && $update 
instanceof EnqueueableDataUpdate ) {
+                                               $spec = 
$update->getAsJobSpecification();
+                                               JobQueueGroup::singleton( 
$spec['wiki'] )->push( $spec['job'] );
+                                       // Otherwise run them now and flush 
transactions if requested
+                                       } else {
+                                               $update->doUpdate();
+                                               if ( $commit === 'commit' ) {
+                                                       
wfGetLBFactory()->commitMasterChanges();
+                                               }
                                        }
                                } catch ( Exception $e ) {
                                        // We don't want exceptions thrown 
during deferred updates to
diff --git a/includes/deferred/LinksUpdate.php 
b/includes/deferred/LinksUpdate.php
index be5aff3..d996870 100644
--- a/includes/deferred/LinksUpdate.php
+++ b/includes/deferred/LinksUpdate.php
@@ -25,7 +25,7 @@
  *
  * @todo document (e.g. one-sentence top-level class description).
  */
-class LinksUpdate extends SqlDataUpdate {
+class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
        // @todo make members protected, but make sure extensions don't break
 
        /** @var int Page ID of the article linked from */
@@ -934,4 +934,16 @@
                        );
                }
        }
+
+       public function getAsJobSpecification() {
+               return array(
+                       'wiki' => $this->mDb->getWikiID(),
+                       'job'  => new JobSpecification(
+                               'refreshLinks',
+                               array( 'prioritize' => true ),
+                               array( 'removeDuplicates' => true ),
+                               $this->getTitle()
+                       )
+               );
+       }
 }
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 708a875..807b987 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -2936,10 +2936,9 @@
 
                // Delete pagelinks, update secondary indexes, etc
                $updates = $this->getDeletionUpdates( $content );
-               // Make sure an enqueued jobs run after commit so they see the 
deletion
-               wfGetDB( DB_MASTER )->onTransactionIdle( function() use ( 
$updates ) {
-                       DataUpdate::runUpdates( $updates, 'enqueue' );
-               } );
+               foreach ( $updates as $update ) {
+                       DeferredUpdates::addUpdate( $update );
+               }
 
                // Reparse any pages transcluding this page
                LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 
'templatelinks' );

-- 
To view, visit https://gerrit.wikimedia.org/r/242649
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8863caef9c8f03234699d33e4d47d2310a0c8446
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to